zoukankan      html  css  js  c++  java
  • 旋转字符串

    旋转字符串

    给定一个字符串(以字符数组的形式给出)和一个偏移量,根据偏移量原地旋转字符串(从左向右旋转)

    样例

    样例  1:
    	输入:  str="abcdefg", offset = 3
    	输出: "efgabcd"
    	
    	样例解释: 
    	返回旋转后的字符串。
    
    样例 2:
    	输入: str="abcdefg", offset = 0
    	输出: "abcdefg"
    	
    	样例解释: 
    	返回旋转后的字符串
    
    样例 3:
    	输入: str="abcdefg", offset = 1
    	输出: "gabcdef"
    	
    	样例解释: 
    	返回旋转后的字符串
    
    样例 4:
    	输入: str="abcdefg", offset =2
    	输出:"fgabcde"
    	
    	样例解释: 
    	返回旋转后的字符串
     1 class Solution:
     2     """
     3     @param str: An array of char
     4     @param offset: An integer
     5     @return: nothing
     6     """
     7     def rotateString(self, str, offset):
     8         # write your code here
     9         if len(str) == 0:
    10             return
    11         n = offset % len(str)
    12         nStr = str[-n:] + str[:-n]
    13         str.clear()
    14         str.extend(nStr)
     
  • 相关阅读:
    bootstrap 兼容 IE8
    在IE8的基础上安装IE11
    前台
    dll 库文件下载地址
    年轻
    linux 异常
    Navicat断网时连不上数据库
    jQuery
    破解版 Teamver 安装
    mysql
  • 原文地址:https://www.cnblogs.com/chentingjun/p/10543347.html
Copyright © 2011-2022 走看看