当前位置:网站首页>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);
}
}
边栏推荐
- STM32 enters and wakes up the stop mode through the serial port
- How to answer the dualistic opposition of Zhihu
- What is AVL tree?
- 微信小程序uploadfile服务器,微信小程序之wx.uploadFile[通俗易懂]
- openresty ngx_ Lua subrequest
- DAY FOUR
- PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
- Close unregistering application XXX with Eureka with status down after Eureka client starts
- DAY FIVE
- DAY THREE
猜你喜欢
DAY TWO
1000字精选 —— 接口测试基础
基于SSM框架实现的房屋租赁管理系统
DAY ONE
从外企离开,我才知道什么叫尊重跟合规…
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
DevOps可以帮助减少技术债务的十种方式
What is AVL tree?
Building lease management system based on SSM framework
Pytest multi process / multi thread execution test case
随机推荐
How to use vector_ How to use vector pointer
Wind chime card issuing network source code latest version - commercially available
DAY TWO
GPIO简介
Huawei mate8 battery price_ Huawei mate8 charges very slowly after replacing the battery
Racher integrates LDAP to realize unified account login
pinia 模块划分
A way of writing SQL, update when matching, or insert
【精品】pinia 基于插件pinia-plugin-persist的 持久化
Pytest multi process / multi thread execution test case
rancher集成ldap,实现统一账号登录
在docker中快速使用各个版本的PostgreSQL数据库
Compile logisim
MATLIB reads data from excel table and draws function image
Devops can help reduce technology debt in ten ways
【CVPR 2022】目标检测SOTA:DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection
自动化测试工具Katalon(Web)测试操作说明
为什么完全背包要用顺序遍历?简要解释一下
17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
Newsletter L Huobi ventures is in-depth contact with genesis public chain