c语言字符串解码leetcode,微软面试题字符串解码以及Leetcode394 字符串解码

第一题:

encode algo: abcde -> c, abde -> cb, ade -> cbd, ae -> cbda, e-> cbdae,相当于每次取剩余字符串的中间字符append

give encode string like cbdae , return raw data string like abcde.

给了deque的解法,问能不能不用dq,然后又换了个方法做、

abcde -> cbdae

规律是这样 先c放中间然后b放左边,d放右边,a放左边,e放右边,如果偶数长度是反过来的。

这题第一次见还是很难想。

第二题:. check 1point3acres for more.

compressed string, 2[abc] -> abcabc, 2[a2[b2[c]]] -> 2[a2[bcc]]-> 2[abccbcc] -> abcbccabcbcc

输入 2[a2[b2[c]]],输出 abcbccabcbcc,lc应该有原题

Leetcode 394题

class Solution {

public:

string decodeString(string s) {

int index = 0;

return helper(s,index);

}

string helper(string s, int& i){

string res;

int num = 0;

while(i

if(s[i]>='0'&&s[i]<='9'){

num = num*10+(s[i]-'0');

}

else if(s[i]=='['){

string str = helper(s, ++i);

for(int i=0;i

res+=str;

}

num = 0;

}else if(s[i]==']'){

return res;

}else{

res+=s[i];

}

i++;

}

return res;

}

};

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值