当前位置:网站首页>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;}}
边栏推荐
猜你喜欢
使用mosquitto过程中的问题解决
yolo格式(txt)数据集转VOC(xml)
DTG-SSOD:最新半监督检测框架,Dense Teacher(附论文下载)
大疆P4M云遮挡矫正
The exchange - string dp
【Acunetix-忘记密码】
【Acunetix-Forgot your password】
How to connect TDengine through DBeaver?
观察者(observer)模式(二) —— 实现线程安全的监听器
- [email protected] This version of tar is no longer supported, and will not receive"/>
npm WARN deprecated [email protected] This version of tar is no longer supported, and will not receive
随机推荐
数字化转型中的低代码
What is the future of smartwatches?
DTG-SSOD:最新半监督检测框架,Dense Teacher(附论文下载)
ansible module --copy module
Create your own app applet ecosystem with applet containers
C#为listview选中的项添加右键菜单
爆款视频怎么做?这里或许有答案!
sva 断言资料
今日睡眠质量记录85分
元宇宙“吹鼓手”Unity:疯狂扩局,悬念犹存
CAN总线的AUTOSAR网络管理
细学常用类,集合类,IO流
基于深度学习的裂缝检测技术
npm WARN deprecated [email protected] This version of tar is no longer supported, and will not receive
AQS-AbstractQueuedSynchronizer
受邀出席Rust开发者大会|Rust如何助力量化高频交易?
大疆P4M云遮挡矫正
企业级数据治理工作怎么开展?Datahub这样做
Kotlin的协程与生命周期
WPF 实现窗体抖动效果