diff --git "a/leetcode3/\354\235\264\354\247\204\355\235\254/226. Invert Binary Tree.java" "b/leetcode3/\354\235\264\354\247\204\355\235\254/226. Invert Binary Tree.java" new file mode 100644 index 000000000..3d66dbc56 --- /dev/null +++ "b/leetcode3/\354\235\264\354\247\204\355\235\254/226. Invert Binary Tree.java" @@ -0,0 +1,31 @@ +/** + * Definition for a binary tree node. + * public class TreeNode { + * int val; + * TreeNode left; + * TreeNode right; + * TreeNode() {} + * TreeNode(int val) { this.val = val; } + * TreeNode(int val, TreeNode left, TreeNode right) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +class Solution { + public TreeNode invertTree(TreeNode root) { + + if (root == null) return null; + + TreeNode tmp = root.left; + root.left = root.right; + root.right = tmp; + + invertTree(root.left); + invertTree(root.right); + + return root; + } + +} \ No newline at end of file