左旋轉字符串

題目

左旋轉字符串

解法

解法1 利用python切片特點

# -*- coding:utf-8 -*-
class Solution:
    def LeftRotateString(self, s, n):
        # write code here
        if not s or n > len(s):
            return ""
        return s[n:]+s[:n]

if __name__ == '__main__':
    test = 'abcdefg'
    s = Solution()
    print(s.LeftRotateString(test, len(test)))
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章