队列模拟

左旋转字符串

http://www.nowcoder.com/questionTerminal/12d959b108cb42b1ab72cef4d36af5ec

string LeftRotateString(string str, int n) {
    queue<char> q;
    for(int i =0 ;i < str.size();i ++)
        q.push(str[i]);
    for(int i =0;i < n;i ++)
    {
        q.push(q.front());
        q.pop();
    }
    string ret;
    while(!q.empty())
    {
        ret += q.front();
        q.pop();
    }
    return ret;
}

跟着感觉直接做的...草稿纸上验证的时候想到一句歌词...太快与你干什么叫莽撞.......好在过了(

全部评论

相关推荐

点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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