Excel Sheet Column Title

来源:互联网 发布:皖都金融网络借贷 编辑:程序博客网 时间:2024/05/12 08:52

Excel Sheet Column Title

此博客主要为自己刷第二次的时候回忆用,代码比较渣,不过会逐渐修改,当然也欢迎交流。

LeetCode 题目地址

第一版代码
>
38 / 38 test cases passed.
Status: Accepted
Runtime: 12 ms
Submitted: 0 minutes ago

/** * Definition for binary tree * struct TreeNode { *     int val; *     TreeNode *left; *     TreeNode *right; *     TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public:    int maxDepth(TreeNode *root) {        int countDepth=0;        int max=0;        TreeNode *p;        queue<TreeNode*> stk;    if(root==NULL)        return 0;        for(stk.push(root);stk.empty()!=true;){            countDepth++;            int time=stk.size();            for(int i=0;i<time;i++){                p=stk.front();                stk.pop();                if(p->left!=NULL)                    stk.push(p->left);                if(p->right!=NULL)                    stk.push(p->right);            }        }        return countDepth;    }};

这个跑起来很慢,还需要重写估计。
if(root==NULL)这个corner最开始没有处理。
同时最开始本来想用压栈,后来变成了queue,每层把队列里的东西都提出来(pop出size大小的),同时从另一方向压入新的,先进后出。没有什么可说的。

0 0
原创粉丝点击