当前位置:网站首页>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;
}边栏推荐
猜你喜欢

Test novice learning classic (with ideas)

Mapreduce实例(一):WordCount

DRF learning notes (II): Data deserialization

Leetcode25 question: turn the linked list in a group of K -- detailed explanation of the difficult questions of the linked list

低代码是开发的未来吗?浅谈低代码平台

MySQL index

时间序列——使用tsfresh进行分类任务

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

COMS Technology

Nacos
随机推荐
Excel extract duplicates
Taking advantage of 5g Dongfeng, does MediaTek want to fight the high-end market again?
Solve the problem that Flink cannot be closed normally after startup
Common problems of mobile terminal H5
Firefox old version
Cubemx联合IAR工程移植
Characters generated by JMeter function assistant in jmeter5.3 and later versions cannot be copied when they are grayed out
Mapreduce实例(一):WordCount
MySQL索引
Personal perception of project optimization
C language programming (Third Edition)
DRF learning notes (IV): DRF view
JWT简介
pdf 提取文字
DRF use: get request to get data (small example)
IO stream introduction
Log management
Rare bitwise operators
Analysis of PHP keyword replacement classes (avoid repeated replacement, keep and restore the original links)
2.2 JMeter基本元件