[LeetCode 111,168][简单]二叉树的最小深度/Excel表列名称

111.二叉树的最小深度
题目链接
之前漏掉了,补上

class Solution {
public:
    int minDepth(TreeNode* root) {
        if(root == NULL)return 0;
        if(root->left && root->right) return min(minDepth(root -> left),minDepth(root -> right)) + 1;
        else return max(minDepth(root -> left),minDepth(root -> right)) + 1;
    }
};

168.Excel表列名称
题目链接

class Solution {
public:
    string convertToTitle(int n) {
        ios::sync_with_stdio(false);
        string ans;
        while(n){
            ans += 'A'+ --n%26;
            n /= 26;
        }
        reverse(ans.begin(),ans.end());
        return ans;
    }
};
发布了104 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/IDrandom/article/details/104199312
今日推荐