File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change 1+ /**
2+ * Definition for a binary tree node.
3+ * function TreeNode(val, left, right) {
4+ * this.val = (val===undefined ? 0 : val)
5+ * this.left = (left===undefined ? null : left)
6+ * this.right = (right===undefined ? null : right)
7+ * }
8+ */
9+ /**
10+ * @param {TreeNode } root
11+ * @return {TreeNode }
12+ */
13+ var invertTree = function ( root ) {
14+ if ( ! root ) return null ;
15+
16+ const queue = [ root ] ;
17+
18+ while ( queue . length > 0 ) {
19+ const current = queue . shift ( ) ;
20+
21+ // ์์ ๋
ธ๋๋ค ๋ฐ๊พธ๊ธฐ
22+ [ current . left , current . right ] = [ current . right , current . left ] ;
23+
24+ // ์์ ๋
ธ๋๋ค์ ํ์ ์ถ๊ฐ
25+ if ( current . left ) queue . push ( current . left ) ;
26+ if ( current . right ) queue . push ( current . right ) ;
27+ }
28+
29+ return root ;
30+ } ;
You canโt perform that action at this time.
0 commit comments