404.左叶子之和
题目链接
static const auto io_speed_up =[](){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
return 0;
}();
class Solution {
public:
int sumOfLeftLeaves(TreeNode* root) {
if(!root)return 0;
TreeNode *left = root -> left;
if(left &&!(left->left)&&!(left->right))return left -> val + sumOfLeftLeaves(root->right) ;
else return sumOfLeftLeaves(root->right) + sumOfLeftLeaves(left);
}
};
405.数字转换为十六进制数
题目链接
static const auto io_speed_up =[](){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
return 0;
}();
class Solution {
public:
string toHex(int num) {
if(!num)return "0";
string ans = "";
unsigned int k = num;
while(k){
int p = k & 15;
if(p<10)ans += to_string(p);
else ans += ('a' + p - 10);
k>>=4;
}
reverse(ans.begin(), ans.end());
return ans;
}
};