We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 139e6c1 commit 929d8d9Copy full SHA for 929d8d9
invert-binary-tree/hyer0705.ts
@@ -0,0 +1,26 @@
1
+/**
2
+ * Definition for a binary tree node.
3
+ * class TreeNode {
4
+ * val: number
5
+ * left: TreeNode | null
6
+ * right: TreeNode | null
7
+ * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
8
+ * this.val = (val===undefined ? 0 : val)
9
+ * this.left = (left===undefined ? null : left)
10
+ * this.right = (right===undefined ? null : right)
11
+ * }
12
13
+ */
14
+
15
+function invertTree(root: TreeNode | null): TreeNode | null {
16
+ if (!root) return null;
17
18
+ const temp = root.left;
19
+ root.left = root.right;
20
+ root.right = temp;
21
22
+ invertTree(root.left);
23
+ invertTree(root.right);
24
25
+ return root;
26
+}
0 commit comments