当前位置:网站首页>【剑指 Offer】58 - II. 左旋转字符串
【剑指 Offer】58 - II. 左旋转字符串
2022-07-03 16:29:00 【LuZhouShiLi】
剑指 Offer 58 - II. 左旋转字符串
题目
字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。比如,输入字符串"abcdefg"和数字2,该函数将返回左旋转两位得到的结果"cdefgab"。
思路
- 反转前N字符串
- 反转n后面的字符串
- 反转整个字符串
代码
class Solution {
public:
string reverseLeftWords(string s, int n) {
// 反转前N字符串
reverse(s.begin(),s.begin() + n);
// 反转n后面的字符串
reverse(s.begin() + n,s.end());
// 反转整个字符串
reverse(s.begin(),s.end());
return s;
}
};
边栏推荐
- 拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
- [proteus simulation] 8 × 8LED dot matrix screen imitates elevator digital scrolling display
- Is it safe to open a stock account by mobile registration? Does it need money to open an account
- ThreeJS 第二篇:顶点概念、几何体结构
- 一台服务器最大并发 tcp 连接数多少?65535?
- 架构实战营 - 第 6 期 毕业总结
- The difference between calling by value and simulating calling by reference
- Rk3399 platform development series explanation (WiFi) 5.54. What is WiFi wireless LAN
- PyTorch 1.12发布,正式支持苹果M1芯片GPU加速,修复众多Bug
- From "zero sum game" to "positive sum game", PAAS triggered the third wave of cloud computing
猜你喜欢

面试官:JVM如何分配和回收堆外内存

Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (II)

Google Earth engine (GEE) - daymet v4: daily surface weather data set (1000m resolution) including data acquisition methods for each day

Initial test of scikit learn Library

QT串口ui设计和解决显示中文乱码

ThreeJS 第二篇:顶点概念、几何体结构

Mysql 将逗号隔开的属性字段数据由列转行

Stm32f103c8t6 firmware library lighting

The accept attribute of the El upload upload component restricts the file type (detailed explanation of the case)

Interviewer: how does the JVM allocate and recycle off heap memory
随机推荐
Mixlab编辑团队招募队友啦~~
中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
One article takes you to understand machine learning
[proteus simulation] 74hc595+74ls154 drive display 16x16 dot matrix
Asemi rectifier bridge umb10f parameters, umb10f specifications, umb10f package
Multithread 02 thread join
"The NTP socket is in use, exiting" appears when ntpdate synchronizes the time
Is it safe to open an account with tongdaxin?
8 tips for effective performance evaluation
Golang 装饰器模式以及在NSQ中的使用
跟我学企业级flutter项目:简化框架demo参考
Register in PHP_ Globals parameter settings
[combinatorics] summary of combinatorial identities (eleven combinatorial identities | proof methods of combinatorial identities | summation methods)*
Slam learning notes - build a complete gazebo multi machine simulation slam from scratch (II)
First knowledge of database
PHP CI (CodeIgniter) log level setting
面试官:JVM如何分配和回收堆外内存
Develop team OKR in the way of "crowdfunding"
2022爱分析· 国央企数字化厂商全景报告
Custom plug-in construction and use of QT plug-in