Skip to content

Commit 6eed7ba

Browse files
committed
Solution: optimize Decode Ways
1 parent 8223d78 commit 6eed7ba

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

decode-ways/flynn.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,27 @@ class Solution {
2727
return memo[s.size()];
2828
}
2929
};
30+
31+
/**
32+
* Space complexity O(1) solution
33+
*/
34+
35+
// class Solution {
36+
// public:
37+
// int numDecodings(string s) {
38+
// if (s[0] == '0') return 0;
39+
40+
// int one_digit_memo = 1, two_digit_memo = 1;
41+
42+
// for (int i = 1; i < s.size(); i++) {
43+
// int tmp = 0;
44+
// if (s[i] != '0') tmp = one_digit_memo;
45+
// int two_digits = stoi(s.substr(i - 1, 2));
46+
// if (10 <= two_digits && two_digits <= 26) tmp += two_digit_memo;
47+
// two_digit_memo = one_digit_memo;
48+
// one_digit_memo = tmp;
49+
// }
50+
51+
// return one_digit_memo;
52+
// }
53+
// };

0 commit comments

Comments
 (0)