类+字符串处理

阅读 50

2022-01-09

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)

0 0 举报