JZ57 二叉树的下一个结点
本文最后更新于:2022年4月9日 中午
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
class Solution { public: TreeLinkNode* GetNext(TreeLinkNode* pNode) { if (pNode->right) { TreeLinkNode* cur = pNode->right; while (cur->left) cur = cur->left; return cur; } while (pNode->next) { TreeLinkNode* cur = pNode->next; if (cur->left == pNode) return cur; pNode = pNode->next; } return nullptr; } };
|