当前位置:网站首页>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);
}
}
边栏推荐
- Use source code compilation to install postgresql13.3 database
- Local deployment Zeppelin 0.10.1
- ldap创建公司组织、人员
- JS import excel & Export Excel
- vector的使用方法_vector指针如何使用
- Three sentences to briefly introduce subnet mask
- 基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】
- 数据运营平台-数据采集[通俗易懂]
- Introduction to GPIO
- Eureka Client启动后就关闭 Unregistering application xxx with eureka with status DOWN
猜你喜欢
Zero code and high return. How to use 40 sets of templates to meet 95% of the reporting needs in the work
Do you still have to rely on Simba to shout for a new business that is Kwai?
GPIO簡介
Hydrogen future industry accelerates | the registration channel of 2022 hydrogen energy specialty special new entrepreneurship competition is opened!
2022/2/10 summary
pytest多进程/多线程执行测试用例
What can the interactive slide screen demonstration bring to the enterprise exhibition hall
从外企离开,我才知道什么叫尊重跟合规…
The "white paper on the panorama of the digital economy" has been released with great emphasis on the digitalization of insurance
Cas d'essai fonctionnel universel de l'application
随机推荐
Tourism Management System Based on jsp+servlet+mysql framework [source code + database + report]
数据运营平台-数据采集[通俗易懂]
iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法
DAY FOUR
Wind chime card issuing network source code latest version - commercially available
Gradle knowledge generalization
C language input / output stream and file operation [II]
DAY TWO
Racher integrates LDAP to realize unified account login
2022/2/11 summary
Use package FY in Oracle_ Recover_ Data. PCK to recover the table of truncate misoperation
app通用功能测试用例
Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
vector的使用方法_vector指针如何使用
零代码高回报,如何用40套模板,能满足工作中95%的报表需求
pytest多进程/多线程执行测试用例
MIT 6.824 - raft Student Guide
A way of writing SQL, update when matching, or insert
GPIO簡介
基于SSM框架实现的房屋租赁管理系统