当前位置:网站首页>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;
}边栏推荐
- 解决flink启动后无法正常关闭
- Characters generated by JMeter function assistant in jmeter5.3 and later versions cannot be copied when they are grayed out
- Leetcode 226 翻转二叉树(递归)
- Mapreduce实例(一):WordCount
- DRF learning notes (IV): DRF view
- Excel提取重复项
- The difference and use between get request and post request
- 4-digit random data
- Find active SQL connections in SQL Server
- Thesis reduction
猜你喜欢

2.2 basic elements of JMeter

Cron expression use

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

新版jmeter函数助手不在选项菜单下-在工具栏中

flume增量采集mysql数据到kafka

MySQL索引

The whereor method of TP5 has many conditions

时间序列-ARIMA模型

减小PDF文档大小(转载)

Characters generated by JMeter function assistant in jmeter5.3 and later versions cannot be copied when they are grayed out
随机推荐
Pychart import existing project
TP5 -- query field contains a certain --find of search criteria_ IN_ SET
TP5 paging some small points
Web test learning notes 01
The 4.3 billion euro cash acquisition of OSRAM failed! AMS said it would continue to acquire
profileapi. h header
Chapter I Marxist philosophy is a scientific world outlook and methodology
EXE程序加密锁
Axure install Icon Font Catalog
For enterprise operation and maintenance security, use the cloud housekeeper fortress machine!
Flume incrementally collects MySQL data to Kafka
爬取常见英文名
插入word中的图片保持高dpi方法
Cubemx联合IAR工程移植
How PHP changes a two-dimensional array into a one-dimensional array
Test novice learning classic (with ideas)
Addition of large numbers
Solve the problem that Flink cannot be closed normally after startup
The difference and use between get request and post request
Common Oracle statements