题目 参考 二分最后一层,每次chek用二分对应节点有没存在。
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
int getd(TreeNode *root) {
int d = 0;
while(root->left) {
++d;
root = root->left;
}
return d;
}
bool ok(TreeNode *root,int &val,int d) {
int l = 0,r = (1
关注
打赏
热门博文