刚带回家一只10周大的小猫.# pets - 心有所宠
S*n
1 楼
A binary search tree is given. Find the ceiling value present in the BST of
a given key. eg-
8
3 12
2 6 10 15
4
key - 13 => 15
key - 4 =>6
key - 8 =>10
自己写了一个
TreeNode* find(TreeNode* root, int target)
{
if(!root) return NULL;
TreeNode * result = NULL;
TreeNode* curr = root;
while( curr )
{
if(target >= curr->val)
curr = curr->right;
else
{
result = curr;
curr = curr->left;
}
}
return result;
}
谁帮我看看对不对,感觉离开leetcode的onlinejudge自己不会测试了
a given key. eg-
8
3 12
2 6 10 15
4
key - 13 => 15
key - 4 =>6
key - 8 =>10
自己写了一个
TreeNode* find(TreeNode* root, int target)
{
if(!root) return NULL;
TreeNode * result = NULL;
TreeNode* curr = root;
while( curr )
{
if(target >= curr->val)
curr = curr->right;
else
{
result = curr;
curr = curr->left;
}
}
return result;
}
谁帮我看看对不对,感觉离开leetcode的onlinejudge自己不会测试了