My solution:
1. Add the first n characters directly after the string
class Solution {
public:
string reverseLeftWords(string s, int n) {
for(int i=0;i<n;i++)
s+=s[i];
return string(s.begin()+n,s.end());
}
};
2. Discover the excellent function of substr ()
s.substr (pos, n), returns a string containing a copy of n characters in s starting from pos
class Solution {
public:
string reverseLeftWords(string s, int n) {
return s.substr(n,s.length()-n+1)+s.substr(0,n);
}
};