Skip to content

Commit dedbc8b

Browse files
91. Decode Ways (java)
1 parent 521980a commit dedbc8b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)