当前位置:网站首页>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;
}边栏推荐
- excel skill
- 2021-03-09
- Chuanyin holdings disclosed that it was prosecuted by Huawei: a case has been filed, involving an amount of 20million yuan
- Install MySQL using CentOS yum
- solidwork装配体导入到Adams中出现多个Part重名和Part丢失的情况处理
- C language programming (Third Edition)
- 201403-1
- Brief description of tenant and multi tenant concepts in cloud management platform
- 爬取常见英文名
- Paper_ Book
猜你喜欢
随机推荐
Have you ever used the comma operator?
Common Oracle statements
Yys mouse connector
云管平台中租户以及多租户概念简单说明
Samsung closes its last mobile phone factory in China
firefox旧版本
第一章 马克思主义哲学是科学的世界观和方法论
Excel提取重复项
flink打包程序提交任务示例
MySQL索引
How PHP changes a two-dimensional array into a one-dimensional array
Mapreduce实例(三):数据去重
Your password does not satisfy the current policy requirements (modify MySQL password policy setting simple password)
Crmeb Pro v1.4 makes the user experience more brilliant!
The first week of C language learning - the history of C language
TP5 query empty two cases
Introduction to JWT
training on multiple GPUs pytorch
Common tool classes under JUC package
Leetcode234 question - simple method to judge palindrome linked list









