题目描述

字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回左旋转两位得到的结果"cdefgab"。

示例 1:

输入: s = "abcdefg", k = 2
输出: "cdefgab"

分析

切片大法好

解题

class Solution:
    def reverseLeftWords(self, s: str, n: int) -> str:
        return s[n:]+s[:n]

 

相关文章:

  • 2021-11-26
  • 2021-06-08
  • 2022-12-23
  • 2021-07-20
  • 2021-06-15
  • 2021-11-13
猜你喜欢
  • 2021-08-11
  • 2022-02-24
  • 2021-10-25
  • 2022-12-23
  • 2021-11-08
  • 2021-09-22
  • 2021-10-15
相关资源
相似解决方案