1.常用方法
to_string()
atoi
s.substr( size_type pos = 0, size_type count = npos )
2. 题目
class Solution {
public:
string countAndSay(int n) {
string s = "1";
for(int i=2; i<=n; i++)
{
string tmp;
for(int j=0; j<s.length(); j++)
{
int k = j;
while(k<s.length() && s[k]==s[j]) //查看有多少个连续相同数字
k++;
tmp += to_string(k-j) + s[j];
j = k-1;
}
s = tmp;
}
return s;
}
};
class Solution {
public:
vector<vector<string>> groupAnagrams(vector<string>& strs) {
for(auto x:strs)
{
auto tmp = x;
sort(tmp.begin(), tmp.end());
m[tmp].push_back(x);
}
vector<vector<string>> ret;
for(auto x:m)
ret.push_back(x.second);
return ret;
}
private:
unordered_map<string, vector<string>> m;
};
1.翻转每个单词
2.翻转整个字符串
class Solution {
public:
string reverseWords(string s) {
int k = 0;
for(int i=0