diff options
| author | mo khan <mo.khan@gmail.com> | 2020-08-23 13:16:26 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-08-23 13:16:26 -0600 |
| commit | b5e7190ecbd1df58e5dd607b1cebeded70cf4b95 (patch) | |
| tree | 3fd0f1a6162476b74feda4ba736e51fcb210b0e5 /2020 | |
| parent | f81a4c5eaa3314c630ba366b171d806c49d6f0bb (diff) | |
Add problem for 08/21
Diffstat (limited to '2020')
| -rw-r--r-- | 2020/08/21/README.md | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/2020/08/21/README.md b/2020/08/21/README.md new file mode 100644 index 0000000..ab6a190 --- /dev/null +++ b/2020/08/21/README.md @@ -0,0 +1,41 @@ +│ You are given the root of a binary tree. Invert the binary tree in +│ place. That is, all left children should become right children, and all +│ right children should become left children. +│ Example: +│ a +│ / \ +│ b c +│ / \ / +│d e f +│ +│ The inverted version of this tree is as follows: +│ a +│ / \ +│ c b +│ \ / \ +│ f e d +│ +│ Here is the function signature: +│class Node: +│ def __init__(self, value): +│ self.left = None +│ self.right = None +│ self.value = value +│ def preorder(self): +│ print self.value, +│ if self.left: self.left.preorder() +│ if self.right: self.right.preorder() +│def invert(node): +│ # Fill this in. +│root = Node('a') +│root.left = Node('b') +│root.right = Node('c') +│root.left.left = Node('d') +│root.left.right = Node('e') +│root.right.left = Node('f') +│root.preorder() +│# a b d e c f +│print "\n" +│invert(root) +│root.preorder() +│# a c f b e d |
