当前位置:网站首页>Likou 58 - Left Rotation String
Likou 58 - Left Rotation String
2022-08-02 11:45:00 【Zhang Ran Ran √】
Title description
The left rotation operation of a string is to transfer several characters in front of the string to the end of the string.Please define a function to implement the function of the left rotation operation of the string.For example, if you enter the string "abcdefg" and the number 2, the function will return the result "cdefgab" obtained by left-rotating it two places.
Solution ideas
- This problem is very simple, just need to figure out StringBuffer's interception string operation function substring();
- Take two strings separately and change the order before and after to spell them together to complete the question.
Input and output example
Code
class Solution {public String reverseLeftWords(String s, int n) {int len = s.length();StringBuffer sb = new StringBuffer();sb.append(s);String s1 = sb.substring(0,n);String s2 = sb.substring(n,len);String ss= s2+s1;return ss;}}
边栏推荐
猜你喜欢
随机推荐
Mysql事务隔离级别与MVCC(多版本并发控制)
华为eNSP(基础实验通信)
Running yum reports Error: Cannot retrieve metalink for reposit
Golang map数组按字段分类
go语言的接口
服务器间传输文件
SQL(面试实战07)
【Acunetix-忘记密码】
CCF paper conference IEEE how to query all articles of a conference journal
[kali-information collection] (1.9) Metasploit + search engine tool Shodan
阿苹的思考
QAbstractScrollArea、QScrollArea
go源码之sync.Waitgroup
借小程序容器打造自有App小程序生态
半夜赶工制作简报的我好想说 : 确定了,最终稿就是这样
SQL函数 TRIM
MP的几种查询方式
When not to use () instead of Void in Swift
MapStruct
元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存