Title: A-"1, B-" 2 ..... The sequence of decoding a string sequence, because there is decoding ambiguity so for example 12-"L or Existence 12-" AB, so the title is given a number string, you can give how many combinations of results:
Personal analysis:
1. There is ambiguity in the existence of 0,1,2 in a given string, so the problem of 0,1,2 should be handled well
2. If the value combination of two numbers is less than 26, there will be a variety of solutions
3. The arrangement of combinatorial learning is not good, and then look at the answer ....
Topic Category:
String, dynamic planning
Learning about Dynamic Planning:
1. Decompose the problem into several sub-problems, similar to the one in which each bit of the string s is decomposed into a sub-problem and then the solution is computed.
2. Once the solution of a given sub-problem has been calculated, then memory storage, so that the next time you need the solution of the same sub-problem to look directly at the table, set up an array, the results of each bit into an array, if the next bit results less than 26, the period result is the first two bits of sums.
3. If the addition of two bits and less than 26 is result[i+1]+result[i+2], if less than 26 is result[i+1];
4. The idea of dynamic planning is to decompose the problem:
For example, in this topic, the string is decomposed into several characters, then analyzed one by one, and the result is finally iterated.
Code:
public int numdecodings (String s) {
int n = s.length ();
if (s==null| | N==0) return 0;
Int[] result = new Int[n+1];
Result[n] = 1;
Result[n-1] = S.charat (n-1)! = ' 0 '? 1:0;
for (int i= n-2; i>=0; i--) {
if (S.charat (i) = = ' 0 ')
Continue
Else
Result[i]= (Integer.parseint (s.substring (i,i+2)) <=26)? Result[i+1]+result[i+2]:result[i+1];
}
return result[0];
}
Decode Ways Problem Solving notes