题解 | #左旋转字符串#
左旋转字符串
https://www.nowcoder.com/practice/12d959b108cb42b1ab72cef4d36af5ec?tpId=13&tqId=23266&ru=/exam/oj/ta&qru=/ta/coding-interviews/question-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param str string字符串 # @param n int整型 # @return string字符串 # class Solution: def LeftRotateString(self , str: str, n: int) -> str: # write code here if not str: return "" #如果移动位数比length大,对length取余数 length=len(str) if n>length: n=n%length Newstr = str[n:]+str[:n] return Newstr