擅长:python、mysql、java
<p>我写过BSTs,但不知道如何使用“array”或“linked list”。以下是我和其他人通常会做的事情:</p>
<pre><code>class TreeNode:
def __init__(self, val):
self.val = val
self.left = self.right = None
class Tree:
def __init__(self):
self.root = None
def add_node(self, val):
# traversing the tree by comparing val with existing node value
...
def remove_node(self, val):
# whatever...
</code></pre>
<p>您将<code>TreeNode</code>存储在<code>Tree</code>中。在</p>