Leetcode - string - Reverse Words in a String
来源:互联网 发布:男士 爽肤水 知乎 混合 编辑:程序博客网 时间:2024/05/21 14:07
class Solution {public: void reverseWords(string &s) { istringstream record(s); string temp; vector<string> vec; while(record>>temp) { vec.push_back(temp); } int theSize=vec.size(); s=""; for(auto i=theSize-1;i>=0;i--) { s=s+vec[i]; if(i!=0) s=s+" "; } }};
不使用vector,直接使用istringstream来解决
/** * 1.s is empty. * 2.s is spaces. * 3.s ends or begins with spaces. */class Solution {public: void reverseWords(string &s) { if(s.empty()) return; istringstream record(s); string str; s.clear(); while(record>>str) { s=str+' '+s; } if(!s.empty()) s.erase(s.end()-1); }};
0 0
- Leetcode - string - Reverse Words in a String
- Reverse words in a String leetcode
- [LeetCode]Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- Reverse Words in a String (LeetCode)
- LeetCode Reverse Words in a String Total
- LeetCode(151)Reverse Words in a String
- Reverse Words in a String -- LeetCode
- leetcode Reverse Words in a String
- LeetCode OJ:Reverse Words in a String
- LeetCode Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- [Leetcode] Reverse Words in a String
- Reverse Words in a String[LeetCode]
- LeetCode OJ :Reverse Words in a String
- Leetcode: Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- 【LeetCode】Reverse Words in a String
- MAC OS X make 命令
- 大四学生发现自己不合企业要求……
- Learn Java for Android Development Second Edition 笔记(一)
- Ubuntu 删除缓存
- URAL 1517 Freedom of Choice
- Leetcode - string - Reverse Words in a String
- NYOJ36&&南阳理工oj_36(动态规划)
- Codeigniter 报错 Unable to connect to your database server using the provided settings
- Linux系统里如何彻底的清空屏幕?
- 服务器端口大全
- 软件设计原则
- cocos2dx 定时器(schedule)的使用及Label类的使用
- DM642图像处理程序的主要结构
- 惊恐,无处可逃!