福田企业网站优化排名,政务移动门户网站建设方案,义乌公司网站制作,帝国企业网站模板力扣题-11.24
[力扣刷题攻略] Re#xff1a;从零开始的力扣刷题生活
力扣题1#xff1a;151. 翻转字符串里的单词
解题思想#xff1a;保存字符串中的单词即可
class Solution(object):def reverseWords(self, s)::type s: str:rtype: str从零开始的力扣刷题生活
力扣题1151. 翻转字符串里的单词
解题思想保存字符串中的单词即可
class Solution(object):def reverseWords(self, s)::type s: str:rtype: strword_list s.split()result for i in range(len(word_list)-1,-1,-1):if i ! 0 :result word_list[i] else:result word_list[i]return resultclass Solution {
public:string reverseWords(string s) {vectorstring wordList splitWords(s);string result ;for (int i wordList.size() - 1; i 0; --i) {if (i ! 0) {result wordList[i] ;} else {result wordList[i];}}return result;}private:vectorstring splitWords(string s) {vectorstring words;istringstream iss(s);string word;while (iss word) {words.push_back(word);}return words;}
};