mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
parent
bd89e83b65
commit
cf337334a5
|
@ -115,20 +115,23 @@
|
|||
"\n",
|
||||
" def get_next(self, node):\n",
|
||||
" if node is None:\n",
|
||||
" raise Exception('Invalid input node')\n",
|
||||
" raise TypeError('node cannot be None')\n",
|
||||
" if node.right is not None:\n",
|
||||
" return self._left_most(node.right)\n",
|
||||
" else:\n",
|
||||
" return self._next_ancestor(node)\n",
|
||||
"\n",
|
||||
" def _left_most(self, node):\n",
|
||||
" if node.left is not None:\n",
|
||||
" return self._left_most(node.left)\n",
|
||||
" else:\n",
|
||||
" return node.data\n",
|
||||
"\n",
|
||||
" def _next_ancestor(self, node):\n",
|
||||
" if node.parent is not None:\n",
|
||||
" if node.parent.data > node.data:\n",
|
||||
" return node.parent.data\n",
|
||||
" else:\n",
|
||||
" return self._next_ancestor(node.parent)\n",
|
||||
" # We reached the root, the original input node\n",
|
||||
" # must be the largest element in the tree.\n",
|
||||
|
|
Loading…
Reference in New Issue
Block a user