/
githubmirror
/
interviews
Обзор
Документация
Войти
/
githubmirror
/
interviews
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
leetcode/tree/InvertBinaryTree.java
38 строк
645 B
Kevin Naughton Jr
finish renaming files and directories
27 мар 2018, 19:52
27 мар 2018, 19:52
ec6dfb5
Код
Авторство
О чём код?
// Invert a binary tree. // 4 // / \ // 2 7 // / \ / \ // 1 3 6 9 // to // 4 // / \ // 7 2 // / \ / \ // 9 6 3 1 /** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class InvertBinaryTree { public TreeNode invertTree(TreeNode root) { if(root == null) { return root; } TreeNode temp = root.left; root.left = invertTree(root.right); root.right = invertTree(temp); return root; } }