leetcode ----394. Decode String
2016-09-25 16:27
441 查看
string decodeString(string s) { string tem; stack<int> stanum; //存储数字 stack<string> stastr;//存储字符串 int n=0; for(int i=0;i<s.length();i++) { if(isdigit(s[i]))//判断当前字符是否为0-9数字 { n = n*10+s[i]-'0';//计算当前数字 } else if(s[i]=='[') { stanum.push(n);//循环次数进栈 n=0;//初始化n stastr.push(tem);//上一次的tem进栈作为top tem.clear();//清空tem } else if(s[i]==']') { int k = stanum.top(); stanum.pop(); for(;k>0;k--) { stastr.top()+=tem;//top累加k次的tem } tem = stastr.top();//把stastr的top赋值给tem stastr.pop(); } else tem+=s[i];//tem一直累加 } return tem; }
相关文章推荐
- Android之获取手机上的图片和视频缩略图thumbnails
- android string.xml文件中的整型和string型代替
- Android java 与 javascript互访(相互调用)的方法例子
- android上改变listView的选中颜色
- String.intern
- Prototype源码浅析 String部分(二)
- Ruby中的String对象学习笔记
- Redis02 使用Redis数据库(String类型)全面解析
- PostgreSQL ERROR: invalid escape string 解决办法
- C#中Byte[]和String之间转换的方法
- C++中sting类的简单实现方法
- 浅谈C++中的string 类型占几个字节
- 标准C++类string的Copy-On-Write技术
- C++实现string存取二进制数据的方法
- 关于C++ string和c类型字符数组的对比
- C#中string和StingBuilder内存中的区别实例分析
- 详解C++中实现继承string类的MyString类的步骤
- PHP STRING 陷阱原理说明
- c#中 String和string的区别介绍
- C#实现的图片、string相互转换类分享