We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 521980a commit dedbc8bCopy full SHA for dedbc8b
solution/0091.Decode Ways/Solution.java
@@ -0,0 +1,19 @@
1
+class Solution {
2
+ public int numDecodings(String s) {
3
+ int len = s.length();
4
+ if (len == 0) return 0;
5
+ int current = s.charAt(0) == '0' ? 0 : 1;
6
+ int last = 1;
7
+ for (int i = 1; i < len; i++) {
8
+ int tmp = current;
9
+ if(s.charAt(i) == '0'){
10
+ if(s.charAt(i-1) == '1' || s.charAt(i-1) == '2') current = last;
11
+ else return 0;
12
+ }else if(s.charAt(i-1) == '1' || s.charAt(i-1) == '2' && s.charAt(i) <= '6') {
13
+ current += last;
14
+ }
15
+ last = tmp;
16
17
+ return current;
18
19
+}
0 commit comments