双向队列

翻转单词顺序列

http://www.nowcoder.com/questionTerminal/3194a4f4cf814f63919d0790578d51f3

  • 声明一个双向队列,先入后出即可满足要求

    class Solution {
    public:
      string ReverseSentence(string str) {
          string tmp="";
          deque<string> de;
          for(auto strnum:str)
          {
              if(strnum==' ')
              {
                  de.push_back(tmp);
                  tmp="";
              }
              else
              {
                  tmp=tmp+strnum;
              }
          }
          de.push_back(tmp);
          string result=de.back();
          de.pop_back();
          while(!de.empty())
          {
              result=result+" "+de.back();
              de.pop_back();
          }
          return result;
    
      }
    };
全部评论

相关推荐

11-07 16:07
深圳大学 运营
前端飞升:学长,阿里不是卡双非吗,我深也能去吗
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务