Skip to content
This repository was archived by the owner on Sep 22, 2021. It is now read-only.

Commit 746ae9e

Browse files
authored
Merge pull request #536 from neaGaze/feature/0091_decode_ways
Added a leetcode solution for problem 0091 Decode Ways for hacktoberfest
2 parents 94c3afd + 975c201 commit 746ae9e

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

LeetCode/0091_Decode_Ways.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def numDecodings(self, s: str) -> int:
3+
def in_range(n):
4+
if n[0] == '0':
5+
return False
6+
to_int = int(n)
7+
if to_int <= 26 and to_int > 0:
8+
return True
9+
return False
10+
11+
N = len(s)
12+
a, b = 1, 1
13+
if N == 0 or s[0] == '0':
14+
return 0
15+
16+
for i in range(1, N):
17+
extra = a if in_range(s[i-1:i+1]) else 0
18+
c = extra + (b if in_range(s[i]) else 0)
19+
a, b = b, c
20+
return b

0 commit comments

Comments
 (0)