mirror of
https://git.wolves.top/wolves/leetcode.git
synced 2025-11-04 17:26:32 +08:00
28 lines
486 B
C++
28 lines
486 B
C++
#include "../structs/Tree.h"
|
|
|
|
using namespace std;
|
|
|
|
TreeNode *getX(TreeNode *root, int x)
|
|
{
|
|
TreeNode *temp = root;
|
|
while (temp)
|
|
{
|
|
if (temp->val > x)
|
|
{
|
|
if (temp->left)
|
|
{
|
|
temp = temp->left;
|
|
continue;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (temp->right)
|
|
{
|
|
temp = temp->right;
|
|
continue;
|
|
}
|
|
}
|
|
return temp;
|
|
}
|
|
} |