Skip to content

Commit

Permalink
Merge pull request #1024 from limlimjo/main
Browse files Browse the repository at this point in the history
[jj7779607] Week10
  • Loading branch information
SamTheKorean authored Feb 16, 2025
2 parents 486a6ef + 38c3322 commit dba1463
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions invert-binary-tree/limlimjo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// 시간 복잡도: O(n)
// 공간 복잡도: O(n)

/**
* 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) return null;

[root.left, root.right] = [invertTree(root.right), invertTree(root.left)];

return root;
};

0 comments on commit dba1463

Please sign in to comment.