当前位置:网站首页>Rotate string left
Rotate string left
2022-07-27 16:25:00 【Cute rain】
Title Description : The left rotation of a string transfers several characters in front of the string to the end of the string . Please define a function to implement the left rotation operation of string . such as : Input string “abcdefg” And number 2, This function will return the result of rotating two bits to the left "cdefgab"
Method 1 solution idea : Since it's a string , We can use it string Member functions of type . Before the string n Insert characters at the end of the string , Then put the front of the front n Delete characters , That's all right. .
Code implementation :
string reverseLeftWords(string s, int n) {
for(int i=0;i<n;i++){
s.push_back(s[i]);
}
s.erase(0,n);
return s;Insert and delete explanations :


Method 2: problem solving ideas : The inversion interval is before n The string of ; The inversion interval is n Substring to the end ; Invert the entire string
Code implementation :
string reveserLeftWords(string s,int n)
{
revese(s.begin(),s.begin()+n);
revese(s.begin()+n,s.end());
revese(s.begin(),s,end());
return s;
}边栏推荐
- Join hands with sifive, Galanz will enter the semiconductor field! Exposure of two self-developed chips
- The difference and use between get request and post request
- Wechat applet personal number opens traffic master
- DRF learning notes (II): Data deserialization
- SolidWorks simulation curve attribute setting
- Web test learning notes 01
- TP5 query empty two cases
- It can carry 100 people! Musk releases the strongest "starship" in history! Go to Mars as early as next year!
- C language programming (Third Edition)
- COMS Technology
猜你喜欢

Cron expression use

知网、万方数据库免费下载论文------比连接学校内网速度快数倍不止(有的学校万方数据库不支持下载)

SolidWorks Simulation曲线图属性设定

2.2 basic elements of JMeter

flume增量采集mysql数据到kafka

Time series ARIMA model

MapReduce instance (I): wordcount

The whereor method of TP5 has many conditions

solidwork装配体导入到Adams中出现多个Part重名和Part丢失的情况处理

The difference and use between get request and post request
随机推荐
DRF learning notes (IV): DRF view
centos yum方式安装mysql
时间序列-ARIMA模型
时间序列——使用tsfresh进行分类任务
Mapreduce实例(二):求平均值
Flume incrementally collects MySQL data to Kafka
google chrome revercecaptcha广告屏蔽
COMS Technology
Axure 安装图标字体元件库
Thesis reduction
The new JMeter function assistant is not under the options menu - in the toolbar
What is ti's calculation for successively canceling the agency rights of anfuli / Wenye / Shiping?
插入word中的图片保持高dpi方法
MapReduce instance (II): Average
Text capture picture (Wallpaper of Nezha's demon child coming to the world)
Leetcode 226 flip binary tree (recursive)
Servlet基础知识点
The whereor method of TP5 has many conditions
profileapi. h header
JSP Foundation