当前位置:网站首页>Leetcode (Sword finger offer) - 58 - ii Rotate string left
Leetcode (Sword finger offer) - 58 - ii Rotate string left
2022-07-01 12:07:00 【Programmer Mu code】
Topic link : Click to open the link
The main idea of the topic : A little .
Their thinking : A little .
Related enterprises
- Bytes to beat
AC Code
- Java
// Solution (1)
class Solution {
public String reverseLeftWords(String s, int n) {
return s.substring(n) + s.substring(0, n);
}
}
// Solution (2)
class Solution {
public String reverseLeftWords(String s, int n) {
StringBuilder res = new StringBuilder();
for(int i = n; i < s.length(); i++)
res.append(s.charAt(i));
for(int i = 0; i < n; i++)
res.append(s.charAt(i));
return res.toString();
}
}
// Solution (3)
class Solution {
public String reverseLeftWords(String s, int n) {
StringBuilder res = new StringBuilder();
for(int i = n; i < n + s.length(); i++)
res.append(s.charAt(i % s.length()));
return res.toString();
}
}- C++
// Solution (1)
class Solution {
public:
string reverseLeftWords(string s, int n) {
return s.substr(n, s.size()) + s.substr(0, n);
}
};
// Solution (2)
class Solution {
public:
string reverseLeftWords(string s, int n) {
reverseString(s, 0, n - 1);
reverseString(s, n, s.size() - 1);
reverseString(s, 0, s.size() - 1);
return s;
}
private:
void reverseString(string& s, int i, int j) {
while(i < j) swap(s[i++], s[j--]);
}
};
// Solution (3)
class Solution {
public:
string reverseLeftWords(string s, int n) {
reverse(s.begin(), s.begin() + n);
reverse(s.begin() + n, s.end());
reverse(s.begin(), s.end());
return s;
}
};边栏推荐
- Message queue monitoring refund task batch process
- [MCU] [nixie tube] nixie tube display
- Computer graduation project asp Net attendance management system vs developing SQLSERVER database web structure c programming computer web page source code project
- [classic example] classic list questions @ list
- Dlhsoft Kanban, Kanban component of WPF
- Redis configuration environment variables
- 内核同步机制
- Value/string in redis
- redis中value/hush
- Is it safe for Huatai Securities to open an account online?
猜你喜欢

The Missing Semester

基于IMDB评论数据集的情感分析

Chen Gong: Micro service, is it still so pure?

Learning summary on June 30, 2022

陈珙:微服务,它还那么纯粹吗?
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2](/img/2b/f42ac6745eb126254af62ad5217f70.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2

Seckill system 03 - redis cache and distributed lock
![[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4](/img/4f/bc6c39ef4f2d1c4bdad8420f7badac.jpg)
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 4

比特熊直播间一周年,英雄集结令!邀你来合影!
![[Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1](/img/be/1194125442aaa2d7cc20b6a4a6762a.jpg)
[Yunju entrepreneurial foundation notes] Chapter VII Entrepreneurial Resource test 1
随机推荐
[Maui] add click events for label, image and other controls
Unity xlua co process packaging
Machine learning - Data Science Library - day two
LeetCode力扣(剑指offer 31-35)31. 栈的压入弹出序列32I.II.III.从上到下打印二叉树33. 二叉搜索树的后序遍历序列34. 二叉树中和为某一值的路径35. 复杂链表的复制
【单片机】【数码管】数码管显示
Personnaliser le plug - in GRPC
JS date format conversion method
谈思生物直播—GENOVIS张洪妍抗体特异性酶切技术助力抗体药物结构表征
Extended tree (I) - concept and C implementation
C serialization simple experiment
Comment Cao définit la décimale de dimension
[Yunju entrepreneurial foundation notes] Chapter 7 Entrepreneurial Resource test 2
Leetcode force buckle (Sword finger offer 31-35) 31 Stack push pop-up sequence 32i II. 3. Print binary tree from top to bottom 33 Post order traversal sequence 34 of binary search tree The path with a
91. (cesium chapter) cesium rocket launch simulation
[classic example] classic list questions @ list
Computer graduation project asp Net hotel room management system VS development SQLSERVER database web structure c programming computer web page source code project
91.(cesium篇)cesium火箭發射模擬
Use of easyexcel
耐克如何常年霸榜第一名?最新财报答案来了
Consolidate -c operator