257.二叉树的所有路径
题目链接
class Solution {
public:
vector<string>ans;
string path="";
void getans(TreeNode* root,string path){
if(root)path += to_string(root->val);
else return ;
if(!(root->left||root->right))ans.emplace_back(path);
else path += "->";
getans(root->left,path);
getans(root->right,path);
}
vector<string> binaryTreePaths(TreeNode* root) {
ios::sync_with_stdio(0);
getans(root,path);
return ans;
}
};
258.各位相加
题目链接
简单证明一下:
class Solution {
public:
int addDigits(int num) {
return (num-1)%9+1;
}
};