Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit807bf07

Browse files
authored
Create decodeWays.py
1 parentd7f4010 commit807bf07

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

‎Kangli/DP/decodeWays.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
3+
4+
5+
6+
7+
8+
O(N)time,O(1)spaceDPvia"general fibonacci numbers"
9+
classSolution(object):
10+
defnumDecodings(self,s):
11+
iflen(s)==0ors[0]=='0':
12+
return0
13+
prev,prev_prev=1,0
14+
foriinxrange(len(s)):
15+
cur=0
16+
ifs[i]!='0':
17+
cur=prev
18+
ifi>0and (s[i-1]=='1'or (s[i-1]=='2'ands[i]<='6')):
19+
cur+=prev_prev
20+
prev,prev_prev=cur,prev
21+
returnprev
22+
23+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp