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 83c9898 commit 67b5404Copy full SHA for 67b5404
226.InvertBinaryTree.kt
@@ -0,0 +1,26 @@
1
+/**
2
+ * Example:
3
+ * var ti = TreeNode(5)
4
+ * var v = ti.`val`
5
+ * Definition for a binary tree node.
6
+ * class TreeNode(var `val`: Int) {
7
+ * var left: TreeNode? = null
8
+ * var right: TreeNode? = null
9
+ * }
10
+ */
11
+//https://leetcode.com/problems/invert-binary-tree/description/
12
+class Solution {
13
+ fun invertTree(root: TreeNode?): TreeNode? {
14
+ if(root == null) return null
15
+
16
+ // Swap left,right child
17
+ val temp = root.left
18
+ root.left = root.right
19
+ root.right = temp
20
21
+ //recurssive
22
+ invertTree(root.left)
23
+ invertTree(root.right)
24
+ return root
25
+ }
26
+}
0 commit comments