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 be6fc51 commit 82ffc9cCopy full SHA for 82ffc9c
0____剑指offer/dynamic_programming/56.num_to_str/solution.cpp
@@ -0,0 +1,30 @@
1
+class Solution
2
+{
3
+public:
4
+ int translateNum(int num)
5
+ {
6
+ std::string str = std::to_string(num);
7
+ vector<int> nums(str.size());
8
+ nums.clear();
9
+ for (auto ch : str)
10
11
+ nums.push_back(ch - 0x30);
12
+ }
13
+ vector<int> dp(str.size()+1);
14
+ dp[0] = 1;
15
+ dp[1] = 1;
16
+ for (int i = 1;i < nums.size();i++)
17
18
+ int current = nums[i - 1] * 10 + nums[i];
19
+ if (current < 26 && current>9)
20
21
+ dp[i + 1] = dp[i] + dp[i - 1];
22
23
+ else
24
25
+ dp[i + 1] = dp[i];
26
27
28
+ return dp.back();
29
30
+};
0 commit comments