leetcodetreenode-invert-binary-tree:反转二叉树

时间:2024-07-21 03:03:10
【文件属性】:

文件名称:leetcodetreenode-invert-binary-tree:反转二叉树

文件大小:771B

文件格式:ZIP

更新时间:2024-07-21 03:03:10

系统开源

leetcode 树节点 反转二叉树 :victory_hand: 反转二叉树。 Example: Input: 4 / \ 2 7 / \ / \ 1 3 6 9 Output: 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; } * } */ class Solution { public TreeNode invertTree ( TreeNode root ) { if (root == null ) return null ; invertTree(root . left); invertTree(root . right); swapChildren(root); return root; } private void swapChildren ( TreeNode node ) {


【文件预览】:
invert-binary-tree-master
----README.md(796B)

网友评论