We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
翻转一棵二叉树。
Input:
4 / \ 2 7 / \ / \ 1 3 6 9
Output:
4 / \ 7 2 / \ / \ 9 6 3 1
The text was updated successfully, but these errors were encountered:
/** * Definition for a binary tree node. * function TreeNode(val, left, right) { * this.val = (val===undefined ? 0 : val) * this.left = (left===undefined ? null : left) * this.right = (right===undefined ? null : right) * } */ /** * @param {TreeNode} root * @return {TreeNode} */ var invertTree = function(root) { if (root === null) { return null; } const invertedLeft = invertTree(root.left); const invertedRight = invertTree(root.right); root.left = invertedRight; root.right = invertedLeft; return root; };
/** * Definition for a binary tree node. * class TreeNode { * val: number * left: TreeNode | null * right: TreeNode | null * constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) { * this.val = (val===undefined ? 0 : val) * this.left = (left===undefined ? null : left) * this.right = (right===undefined ? null : right) * } * } */ function invertTree(root: TreeNode | null): TreeNode | null { if (root === null) { return null; } const invertedLeft = invertTree(root.left); const invertedRight = invertTree(root.right); root.left = invertedRight; root.right = invertedLeft; return root; };
Sorry, something went wrong.
No branches or pull requests
226. Invert Binary Tree
翻转一棵二叉树。
Example
Input:
Output:
The text was updated successfully, but these errors were encountered: