KimMinJun
Coding Note
KimMinJun
전체 방문자
오늘
어제
  • 분류 전체보기 (486)
    • ALGORITHM (11)
      • 정렬 (6)
      • 최단경로 (1)
      • 자료구조 (1)
      • 슬라이딩 윈도우 (1)
      • etc (2)
    • Git (5)
    • Web (24)
      • Vanilla JS (13)
      • TS (2)
      • React (7)
      • ETC (1)
    • React 공식문서 (번역, 공부) (11)
      • Quick Start (2)
      • Installation (0)
      • Describing the UI (9)
      • Adding Interactivity (0)
      • Managing State (0)
      • Escape Hatches (0)
    • Next.js 공식문서 (번역, 공부) (3)
      • Getting Started (2)
      • Building Your Application (1)
    • PS (431)
      • 백준 (187)
      • Programmers (104)
      • CodeUp (21)
      • STL (3)
      • 제코베 JS 100제 (50)
      • SWEA (0)
      • LeetCode (65)
    • IT (1)

블로그 메뉴

  • 홈
  • 태그
  • 방명록
  • 관리

공지사항

인기 글

태그

  • 문자열
  • Level1
  • 제코베 JS 100제
  • programmers
  • 그래프
  • Level 2
  • codeup
  • js
  • C++
  • 다이나믹 프로그래밍
  • Level 0
  • Level 1
  • 수학
  • LeetCode
  • string
  • 백준
  • recursion
  • tree
  • 정렬
  • C

최근 댓글

최근 글

hELLO · Designed By 정상우.
KimMinJun
PS/LeetCode

LeetCode / Tree / 226번 / Invert Binary Tree / JS

PS/LeetCode

LeetCode / Tree / 226번 / Invert Binary Tree / JS

2023. 4. 28. 17:28

< 문제 바로가기 >

 

Invert Binary Tree - LeetCode

Can you solve this real interview question? Invert Binary Tree - Given the root of a binary tree, invert the tree, and return its root.   Example 1: [https://assets.leetcode.com/uploads/2021/03/14/invert1-tree.jpg] Input: root = [4,2,7,1,3,6,9] Output: [4

leetcode.com

 

< 문제 간단설명 >

주어진 트리를 좌우반전시켜 반환하는 문제이다.

 

/**
 * 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 root;
    }

    invertTree(root.left);
    invertTree(root.right);

    [root.left, root.right] = [root.right, root.left];

    return root;
};
저작자표시

'PS > LeetCode' 카테고리의 다른 글

LeetCode / Tree / 543번 / Diameter of Binary Tree / JS  (0) 2023.04.28
LeetCode / Tree / 110번 / Balanced Binary Tree / JS  (0) 2023.04.28
LeetCode / Greedy / 621번 / Task Scheduler / JS  (0) 2023.04.28
LeetCode / Greedy / 2131번 / Longest Palindrome by Concatenating Two Letter Words / JS  (0) 2023.04.28
    'PS/LeetCode' 카테고리의 다른 글
    • LeetCode / Tree / 543번 / Diameter of Binary Tree / JS
    • LeetCode / Tree / 110번 / Balanced Binary Tree / JS
    • LeetCode / Greedy / 621번 / Task Scheduler / JS
    • LeetCode / Greedy / 2131번 / Longest Palindrome by Concatenating Two Letter Words / JS
    KimMinJun
    KimMinJun

    티스토리툴바

    개인정보

    • 티스토리 홈
    • 포럼
    • 로그인

    단축키

    내 블로그

    내 블로그 - 관리자 홈 전환
    Q
    Q
    새 글 쓰기
    W
    W

    블로그 게시글

    글 수정 (권한 있는 경우)
    E
    E
    댓글 영역으로 이동
    C
    C

    모든 영역

    이 페이지의 URL 복사
    S
    S
    맨 위로 이동
    T
    T
    티스토리 홈 이동
    H
    H
    단축키 안내
    Shift + /
    ⇧ + /

    * 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.