题解 | #左旋转字符串#
左旋转字符串
http://www.nowcoder.com/practice/12d959b108cb42b1ab72cef4d36af5ec
用queue,从头移出来的添加到尾部。
class Solution { public: string LeftRotateString(string str, int n) { string ans = ""; queue<char> q; for(char& c : str) q.push(c); while(n != 0) { q.push(q.front()); q.pop(); n--; } while(q.empty() == 0) { ans += q.front(); q.pop(); } return ans; } };