/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* searchBST(struct TreeNode* root, int val) {
if(!root) return NULL;
while(root){
if(root->val==val) return root;
if(root->val>val){
root=root->left;
}else{
root=root->right;
}
}
return NULL;
}
结果:
标签:TreeNode,struct,val,root,700,搜索,return,树中 From: https://www.cnblogs.com/llllmz/p/18056335