Skip to content

Commit feeb561

Browse files
committed
Update decode-ways.py
1 parent 0938e19 commit feeb561

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Python/decode-ways.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,25 @@
1515
# The number of ways decoding "12" is 2.
1616
#
1717

18-
class Solution:
19-
# @param s, a string
20-
# @return an integer
18+
class Solution(object):
2119
def numDecodings(self, s):
20+
"""
21+
:type s: str
22+
:rtype: int
23+
"""
2224
if len(s) == 0 or s[0] == '0':
2325
return 0
2426
prev, prev_prev = 1, 0
2527
for i in xrange(len(s)):
26-
current = 0
28+
cur = 0
2729
if s[i] != '0':
28-
current = prev
30+
cur = prev
2931
if i > 0 and (s[i - 1] == '1' or (s[i - 1] == '2' and s[i] <= '6')):
30-
current += prev_prev
31-
prev, prev_prev = current, prev
32+
cur += prev_prev
33+
prev, prev_prev = cur, prev
3234
return prev
33-
35+
36+
3437
if __name__ == "__main__":
3538
for i in ["0", "10", "10", "103", "1032", "10323"]:
3639
print Solution().numDecodings(i)

0 commit comments

Comments
 (0)