0
点赞
收藏
分享

微信扫一扫

类+字符串处理

GhostInMatrix 2022-01-09 阅读 41
开发语言

1.题目引入:

2.样例输出:

3.代码如下:

利用 STL容器:

class Solution {
public:
    string leftRotateString(string str, int n) {
          return str.substr(n)+str.substr(0,n);
    }
};

直接利用 string 的字符串特性:

python 做法:

class Solution(object):
    def leftRotateString(self, s, n):
        """
        :type s: str
        :type n: int
        :rtype: str
        """
        return s[n:] + s[:n]
举报

相关推荐

0 条评论