当前位置:网站首页>[sword finger offer] sword finger offer 58 - ii Rotate string left
[sword finger offer] sword finger offer 58 - ii Rotate string left
2022-06-12 21:52:00 【Caicai 2022】
subject
Code
Execution time :36 ms, In all Python3 Defeated in submission 61.20% Users of
Memory consumption :15 MB, In all Python3 Defeated in submission 78.80% Users of
Pass the test case :34 / 34
class Solution:
def reverseLeftWords(self, s: str, n: int) -> str:
return s[n:]+s[:n]
【 Method 2】
Execution time :36 ms, In all Python3 Defeated in submission 61.20% Users of
Memory consumption :15.1 MB, In all Python3 Defeated in submission 38.62% Users of
Pass the test case :34 / 34
class Solution:
def reverseLeftWords(self, s: str, n: int) -> str:
ans=[' ']*len(s)
for i in range(len(s)):
if i>=n:
ans[i-n]=s[i]
else:
ans[len(s)-n+i]=s[i]
return "".join(ans)
【 Method 3】
Execution time :36 ms, In all Python3 Defeated in submission 61.20% Users of
Memory consumption :15.1 MB, In all Python3 Defeated in submission 37.15% Users of
Pass the test case :34 / 34
class Solution:
def reverseLeftWords(self, s: str, n: int) -> str:
ans=[]
for i in range(n,n+len(s)):
ans.append(s[i%len(s)])
return "".join(ans)
边栏推荐
- Turing prize winner: what should I pay attention to if I want to succeed in my academic career?
- Ansible PlayBook et ansible roles (3)
- "Oracle database parallel execution" technical white paper reading notes
- 如何自己动手写一个vscode插件,实现插件自由!
- June training (day 10) - bit operation
- How to ensure thread safety?
- SQL tuning guide notes 14:managing extended statistics
- Graphics2D类基本使用
- MySQL体系结构及基础管理(二)
- You can move forward or backward. This function in idea is amazing!
猜你喜欢

User guide for JUC concurrency Toolkit

SQL调优指南笔记10:Optimizer Statistics Concepts

SQL调优指南笔记17:Importing and Exporting Optimizer Statistics

Jin AI her power | impact tech, she can

Cloning PDB with ADG standby

PCB封装下载网站推荐及其详细使用方法

A puzzle about + =

SQL tuning guide notes 10:optimizer statistics concepts

回文链表及链表相交问题(和心怡的人相交)你真的会了吗?

JUC并发工具包使用指南
随机推荐
Oracle 19C installation documentation
MySQL体系结构及基础管理(二)
ICML2022 | GALAXY:極化圖主動學習
【QNX Hypervisor 2.2 用户手册】4.4 构建Host
Oracle 19c 安装文档
SQL调优指南笔记13:Gathering Optimizer Statistics
JdbcTemplate插入并返回主键
selenium操作元素遇到的异常
A puzzle about + =
关于 安装Qt5.15.2启动QtCreator后“应用程序无法正常启动0xc0000022” 的解决方法
Ansible playbook和变量(二)
The ifeq, filter and strip of makefile are easy to use
Recommended Chinese font in the code input box of Oracle SQL developer
SQL tuning guide notes 14:managing extended statistics
June training (day 10) - bit operation
MySql主从复制
How to implement a simple publish subscribe mode
MySQL architecture and basic management (II)
孙老师版本JDBC(2022年6月12日21:34:25)
SQL调优指南笔记6:Explaining and Displaying Execution Plans