The title

Left-rotation of a string moves several characters from the beginning to the end of the string. Define a function to rotate the string left. For example, if you enter the string “abcdefg” and the number 2, the function will return “cdefgab” as a result of the left rotation.

 

Example 1: Input: s = "abcdefg", k = 2 Output: "cdefgab" Example 2: Input: s = "lrloseumgh", k = 6 Output: "umghlrlose"Copy the code

Limitations:

1 <= k < s.length <= 10000

Their thinking

class Solution: def reverseLeftWords(self, s: str, n: int) -> str: # res = s + s # joining together into two segments, then slice # return res [n, n + len (s)] return s/n: + s [: n] if __name__ = = "__main__ ': s = "abcdefg" k = 2 result = Solution().reverseLeftWords(s, k) print(result)Copy the code