classSolution { public: stringreverseLeftWords(string s, int n){ string ans = ""; for (int i = n; i < s.size(); ++i) ans += s[i]; for (int i = 0; i < n; ++i) ans += s[i]; return ans; } };
解法二:
思路:
切片一:
代码:
1 2 3 4 5 6
classSolution { public: stringreverseLeftWords(string s, int n){ return (s + s).substr(n, s.size()); } };