lintcode:旋转字符串
来源:互联网 发布:mac 数据库管理工具 编辑:程序博客网 时间:2024/04/29 01:35
class Solution: # @param s: a list of char # @param offset: an integer # @return: nothing def rotateString(self, s, offset): # write you code here # 198ms if not s:return s n = len(s) offset = offset % n if not s:return s for i in range(offset): t = s.pop() s.insert(0,t) # 189ms 分别赋值 if not s:return s n = len(s) offset = offset % n if not offset:return s temp_pre = s[-offset:] temp_las = s[0:n-offset] m = len(temp_pre) for i in range(len(temp_pre)): s[i] = temp_pre[i] for i in range(len(temp_pre), n): s[i] = temp_las[i - m] # 206ms 字符串 * 2 if not s:return s n = len(s) offset = offset%n if not offset:return s temp = s*2 for i in range(n): s[i] = temp[n-offset+i] # 198ms 互换位置 if not s: return s n = len(s) offset = offset % n if not offset:return s s[0:n-offset], s[-offset:] = s[-offset:], s[0:n-offset] # 226ms 三次反转 if not s:return s n = len(s) offset = offset % n if not offset:return s s[0:n-offset] = reversed(s[0:n-offset]) s[-offset:] = reversed(s[-offset:]) s[::] = reversed(s)
阅读全文
0 0
- LintCode:旋转字符串
- lintcode ----旋转字符串
- LintCode 8 旋转字符串
- Lintcode 旋转字符串
- LintCode 旋转字符串
- lintcode--旋转字符串
- LintCode之旋转字符串
- [LintCode]8.旋转字符串
- 【LintCode】旋转字符串
- lintcode:旋转字符串
- Lintcode:旋转字符串
- 【LintCode】Rotate String 旋转字符串
- LintCode C++代码旋转字符串
- LintCode之8 旋转字符串
- (lintcode)第8题旋转字符串
- LintCode-旋转链表
- LintCode-旋转图像
- LintCode-旋转链表
- linux监控命令
- Spring框架简单理解
- c#连接到sql server2008数据库
- spring-cloud-netflix编译错误
- Codeforces Codeforces Round #432 (Div. 2 D ) Arpa and a list of numbers
- lintcode:旋转字符串
- 在java中要将字符串转换为日期格式,则要使用SimpleDateFormat类中的parse方法 format方法传入的参数格式含义说明: yyyy:表示四位年 MM:表示月份 dd:表示日子 HH
- Scala-Spark digamma stackoverflow问题
- JavaWeb 自定义标签&EL自定义函数
- 【线段树 && 离线处理 && 维护区间规定下标的和】HDU
- 浅谈Android开发中的MVVM模式及与MVP和MVC的区别
- sqlServer数据库备份
- POI常用操作
- oracle常用语句