We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8223d78 commit 6eed7baCopy full SHA for 6eed7ba
decode-ways/flynn.cpp
@@ -27,3 +27,27 @@ class Solution {
27
return memo[s.size()];
28
}
29
};
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