From 561b3d9f611e1e41e6c0a765d53e6c57f2783a8c Mon Sep 17 00:00:00 2001 From: SinnoLn Date: Fri, 18 Sep 2026 23:41:28 +0900 Subject: [PATCH] 226. Invert Binary Tree --- .../226. Invert Binary Tree.java" | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 "leetcode3/\354\235\264\354\247\204\355\235\254/226. Invert Binary Tree.java" 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