我的题解,言简意赅

左旋转字符串

https://www.nowcoder.com/practice/12d959b108cb42b1ab72cef4d36af5ec

class Solution {
public:
    string LeftRotateString(string str, int n) {
        int len = str.size();
        if(len == 0)
            return "";
        n = n%len;
        string temp(str,0,n);
        str+=temp;
        str.erase(0,n);
        return str;
    }
};

全部评论

相关推荐

不愿透露姓名的神秘牛友
11-19 14:56
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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