151.翻转字符串里的单词 卡码网:55.右旋转字符串
151.翻转字符串里的单词 卡码网:55.右旋转字符串
151.翻转字符串里的单词
题目链接 :
Code :
class Solution {
public:
string reverseWords(string s) {
// 单词 级 翻转 , 而 不是 单词 内 翻转
// 栈
stack<string> stack_For_Word ;
// 清理
// / 跳 至 第一个 有效 字符 / 字母
int i_Work = 0 ;
while(s[i_Work] == ' ' )
{
i_Work ++ ;
}
//string str_Cache_For_Word = "" ;
while(s[i_Work] != '\0')
{
while(s[i_Work] == ' ' )
{
i_Work ++ ;
}
int Find = 0 ;
string str_Cache_For_Word = "";
while(s[i_Work] != ' ' && s[i_Work] != '\0' )
{
str_Cache_For_Word += s[i_Work] ;
i_Work ++ ;
Find = 1 ;
}
if(Find == 1 )
{
stack_For_Word.push(str_Cache_For_Word);
}
// “ 空 串 被 添加 进去 了 ”
// need Check
// i_Work ++ ;
}
string str_For_Return = "";
while(stack_For_Word.empty() != true)
{
string str_Cache_For_Word = stack_For_Word.top();
str_For_Return += str_Cache_For_Word ;
stack_For_Word.pop();
if(stack_For_Word.empty() != true)
{
str_For_Return += " " ;
}
}
return str_For_Return ;
}
};
卡码网:55.右旋转字符串
题目链接 :
Code :
