本文主要是介绍C++ | Leetcode C++题解之第91题解码方法,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目:
题解:
class Solution {
public:int numDecodings(string s) {int n = s.size();// a = f[i-2], b = f[i-1], c = f[i]int a = 0, b = 1, c;for (int i = 1; i <= n; ++i) {c = 0;if (s[i - 1] != '0') {c += b;}if (i > 1 && s[i - 2] != '0' && ((s[i - 2] - '0') * 10 + (s[i - 1] - '0') <= 26)) {c += a;}tie(a, b) = {b, c};}return c;}
};
这篇关于C++ | Leetcode C++题解之第91题解码方法的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!