LeetCode Reverse Words in a String(反转字符串)
来源:互联网 发布:无线wifi网络电视 编辑:程序博客网 时间:2024/05/16 14:10
class Solution {public: void reverseWords(string &s) {if(s=="");else{vector<string> vec;int start = 0;for(int i=0;i<s.length();i++){if(s.at(i)==' '){vec.push_back(s.substr(start,i-start));start = i+1;}else if(i == s.length()-1){vec.push_back(s.substr(start,i+1 - start)); }}std::reverse(vec.begin(),vec.end());vector<string>::iterator iter = vec.begin();s.erase();while(iter != vec.end()){s+=*iter+" ";iter++;}s.erase(s.length()-1);}cout<<s<<endl; }};
第一次写的代码:
0 0
- LeetCode Reverse Words in a String(反转字符串)
- LeetCode Reverse Words in a String(反转字符串)
- 字符串反转 reverse-words-in-a-string @LeetCode
- [leetcode, python] Reverse Words in a String 反转字符串
- [LeetCode]Reverse Words in a String-反转单词
- [Leetcode] reverse words in a string 反转单词
- LeetCode 151. Reverse Words in a String(反转单词)
- Reverse Words in a String 字符串中单词反转
- LeetCode | Reverse Words in a String(字符串中的单词序反转)
- [LeetCode]557. Reverse Words in a String III(反转字符串 III)
- LeetCode 557 Reverse Words in a String III(反转字符串中的单词3)
- leetcode Reverse Words in a String III 反转字符串中的单词
- Leetcode【字符串】: Reverse Words in a String 要点分析
- leetcode 151. Reverse Words in a String 字符串 翻转
- LeetCode 151 Reverse Words in a String (字符串处理 推荐)
- 字符串-leetcode 557 Reverse Words in a String III
- leetcode 151. Reverse Words in a String 字符串分割逆序
- Leetcode - string - Reverse Words in a String
- 以实例来说明strlen()和sizeof()的区别
- ibatis源码探究
- NYOJ524 A-B Problem
- 炉石传说iPad版抢鲜玩 最全国服登录教程
- javascript实现添加收藏功能,对于Chrom,webkit内核浏览器提醒热键添加
- LeetCode Reverse Words in a String(反转字符串)
- Python中赋值、浅拷贝与深拷贝
- 二分查找的正确姿势
- C++构造、析构和赋值
- windows编程(三)GDI入门(续)
- 【学习记录】简单线程池的实现
- The connection to adb is down, and a severe error has occured.(二)
- ubuntu默认root密码问题
- 24点游戏 Java 递归