classSolution{
public:intnumDecodings(string s){
int n = s.size();
s =' '+ s;//为了方便,让下标从1开始,所以加上一个空格
vector<int>f(n +1);
f[0]=1;//0个数字是的解码方案算作1for(int i =1; i <= n; i ++){
if(s[i]>='1'&& s[i]<='9') f[i]+= f[i -1];if(i >1){
int t =(s[i -1]-'0')*10+(s[i]-'0');if(t >=10&& t <=26) f[i]+= f[i -2];}}return f[n];}};
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/classSolution{
public:
ListNode*reverseBetween(ListNode* head,int m,int n){
auto dummy =newListNode(-1);
dummy->next = head;auto a = dummy;for(int i =0; i < m -1; i ++) a = a->next;//前进m - 1步找到a点;auto b = a->next, c = b->next;//来反转m~n之间的链表for(int i =0; i < n - m; i ++){
auto t = c->next;
c->next = b;
b = c, c = t;}
a->next->next = c;//再将首尾相接
a->next = b;return dummy->next;}};
classSolution{
public:
vector<string> ans;
vector<string>restoreIpAddresses(string s){
dfs(s,0,0,"");return ans;}//u表示枚举到的字符串下标,k表示当前截断的IP个数,s表示原字符串voiddfs(string&s,int u,int k, string path){
if(u == s.size()){
if(k ==4){
path.pop_back();//记得将上次搜索的最后一个点去掉
ans.push_back(path);}return;}if(k >4)return;//剪枝,多余4个就不搜了,没有这句会TLEfor(int i = u, t =0; i < s.size(); i ++){
if(i > u && s[u]=='0')break;//至少有两位并且有前导0
t = t *10+ s[i]-'0'
91. 解码方法class Solution {public: int numDecodings(string s) { int n = s.size(); s = ' ' + s;//为了方便,让下标从1开始,所以加上一个空格 vector<int> f(n + 1); f[0] = 1;//0个数字是的解码方案算作1 for (int i = 1; i <= n; i ++ ) {