Decode Ways
class Solution { private: vector<int> f; public: int getF(int index) { if (index < 0) return 1; else return f[index]; } int numDecodings(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function if (s.size() == 0) return 0; f.resize(s.size()); for(int i = 0; i < s.size(); i++) { f[i] = 0; if (i >= 1) { string a(s, i - 1, 2); if ("10" <= a && a <= "26") f[i] += getF(i-2); if ('1' <= s[i] && s[i] <= '9') f[i] += getF(i-1); } else { if ('1' <= s[i] && s[i] <= '9') f[i] = 1; } } return f[f.size() - 1]; } };