当前位置:网站首页>Leecode brush question record sword finger offer 58 - ii Rotate string left
Leecode brush question record sword finger offer 58 - ii Rotate string left
2022-07-07 00:12:00 【Why is there a bug list】
topic
The left rotation operation of string is to transfer several characters in front of string to the end of string . Please define a function to implement the left rotation operation of string . such as , Input string "abcdefg" And number 2, This function will return the result of rotating two bits to the left "cdefgab".
Example 1:
Input : s = “abcdefg”, k = 2
Output : “cdefgab”
Example 2:
Input : s = “lrloseumgh”, k = 6
Output : “umghlrlose”
Limit :
1 <= k < s.length <= 10000
answer
class Solution {
public String reverseLeftWords(String s, int n) {
char[] chars=s.toCharArray();
char[] tmpchars=new char[n];
int i=0;
for(; i< tmpchars.length; i++)
{
tmpchars[i]=chars[i];
}
for(int j=n;j<s.length();j++)
{
chars[j-n]=chars[j];
}
i=0;
for(int k=s.length()-n;k<s.length();k++)
{
chars[k]=tmpchars[i];
i++;
}
return new String(chars);
}
}
边栏推荐
猜你喜欢
pytest多进程/多线程执行测试用例
Cas d'essai fonctionnel universel de l'application
Devops can help reduce technology debt in ten ways
服务器SMP、NUMA、MPP体系学习笔记。
DAY SIX
【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤
Three application characteristics of immersive projection in offline display
app通用功能測試用例
STM32通过串口进入和唤醒停止模式
Competition between public and private chains in data privacy and throughput
随机推荐
17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
okcc呼叫中心的订单管理时怎么样的
PostgreSQL使用Pgpool-II实现读写分离+负载均衡
[CVPR 2022] semi supervised object detection: dense learning based semi supervised object detection
基于SSM框架实现的房屋租赁管理系统
Do you still have to rely on Simba to shout for a new business that is Kwai?
2022 PMP project management examination agile knowledge points (9)
Rider离线使用Nuget包的方法
(LeetCode)两数之和
DAY THREE
为什么完全背包要用顺序遍历?简要解释一下
Random类的那些事
华为mate8电池价格_华为mate8换电池后充电巨慢
SQL的一种写法,匹配就更新,否则就是插入
Geo data mining (III) enrichment analysis of go and KEGG using David database
MIT 6.824 - raft Student Guide
vector的使用方法_vector指针如何使用
MATLIB reads data from excel table and draws function image
Server SMP, NUMA, MPP system learning notes.
How to find out if the U disk file of the computer reinstallation system is hidden