当前位置:网站首页>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;}}边栏推荐
猜你喜欢
随机推荐
从幻核疑似裁撤看如何保证NFT的安全
暑期总结3
QT笔记——Q_PROPERTY了解
Create your own app applet ecosystem with applet containers
ASP.NET Core 6框架揭秘实例演示[31]:路由“高阶”用法
SQLAlchemy使用教程
解决anaconda下载pytorch速度极慢的方法
X86函数调用模型分析
AdguardHome如何配置设置?我的AdguardHome配置内容过滤器拦截列表
8大软件供应链攻击事件概述
Learning Experience Sharing Seven: YOLOv5 Code Chinese Comments
Challenge LeetCode1000 questions in 365 days - Day 047 Design Circular Queue Circular Queue
QListView的使用
ssm网页访问数据库数据报错
放苹果(暑假每日一题 13)
The exchange - string dp
免费文档翻译-免费批量文档翻译软件推荐
redis cluster cluster, the ultimate solution?
如何通过DBeaver 连接 TDengine?
SQL函数 $TRANSLATE









