0%

剑指 Offer 58 - II. 左旋转字符串

剑指 Offer 58 - II. 左旋转字符串

花里胡哨的,真无语

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution {
public:
string reverseLeftWords(string s, int n) {
vector<char> a;
for(int i = 0 ; i<s.size();i++){
if(i>=n) a.push_back(s[i]);
}
for(int i = 0 ; i<s.size();i++){
if(i<n) a.push_back(s[i]);
}

string result(a.begin(),a.end());
return result;
}
};
1
2
3
4
5
6
7
8
9
class Solution(){
public:
string reverseLeftWords(string s,int n){
reverse(s.begin(),s.begin()+n)
reverse(s.begin()+n,s.end())
reverse(s.begin(),s.end())
return s;
}
}
-------------本文结束感谢您的阅读-------------
老板你好,讨口饭吃