diff --git a/csharp/226-Invert-Binary-Tree.cs b/csharp/226-Invert-Binary-Tree.cs new file mode 100644 index 000000000..ec517ad24 --- /dev/null +++ b/csharp/226-Invert-Binary-Tree.cs @@ -0,0 +1,29 @@ +/** + * Definition for a binary tree node. + * public class TreeNode { + * public int val; + * public TreeNode left; + * public TreeNode right; + * public TreeNode(int val=0, TreeNode left=null, TreeNode right=null) { + * this.val = val; + * this.left = left; + * this.right = right; + * } + * } + */ +public class Solution +{ + public TreeNode InvertTree(TreeNode root) + { + if (root == null) return null; + + var tmp = root.left; + root.left = root.right; + root.right = tmp; + + InvertTree(root.left); + InvertTree(root.right); + + return root; + } +} \ No newline at end of file