/** 91. Decode ways * 12.20 by mingyang * meaning resolution: give you a string of numbers and decode them into English letters. * It is similar to the stair climb problem, but many restrictions need to be added. * Defining array number, number [I] means: String s [0 .. I-1] can have number [I] decoding method. * Recall the same as the stair climb problem, number [I] = number [I-1] + number [I-2] * but the difference is that the subject has a variety of restrictions: * first: s [I-1] cannot be 0, if s [I-1] is 0, number [I] can only be equal to number [I-2] --- the end number cannot be 0 * For example, the number of 110 is the same as 1 (two less) * Second, s [I-2, the first character in the I-1] cannot be 0, and integer. parseint (S. the integer obtained by substring (I-2, I) must be between 0 and 26. * The first digit of the last two digits is not 0 */Public int numdecodings (string s) {If (S = NULL | S. length () = 0) {return 0;} If (S. charat (0) = '0') {return 0;} int [] Number = new int [S. length () + 1]; number [0] = 1; number [1] = 1; int TMP; For (INT I = 2; I <= S. length (); I ++) {// check whether the current character is '0' TMP = integer. parseint (S. substring (I-1, I); If (TMP! = 0) {number [I] = number [I-1];} // check whether the current character and the previous character are combined between 1-26 if (S. charat (I-2 )! = '0') {TMP = integer. parseint (S. substring (I-2, I); If (TMP> 0 & TMP <= 26) {number [I] + = number [I-2] ;}} return number [S. length ()];}
91. Decode ways