๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿƒ algorithm/leetcode

LeetCode 94 - Binary Tree Inorder Traversal (Medium)

by HandHand 2021. 3. 3.

๋ฌธ์ œ

LeetCode - 94๋ฒˆ

ํ’€์ด ๊ณผ์ •

์ด์ง„ ๊ฒ€์ƒ‰ ํŠธ๋ฆฌ์˜ ์ค‘์œ„ ์ˆœํšŒ ๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฌธ์ œ์ž…๋‹ˆ๋‹ค.

์žฌ๊ท€ ํ˜ธ์ถœ ์„ ์ด์šฉํ•ด์„œ ์™ผ์ชฝ ์„œ๋ธŒํŠธ๋ฆฌ, ์„œ๋ธŒ ๋ฃจํŠธ, ์˜ค๋ฅธ์ชฝ ์„œ๋ธŒํŠธ๋ฆฌ ์ˆœ์„œ๋กœ ๋ฐฉ๋ฌธํ•ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

์ฝ”๋“œ

/**
 * 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 {number[]}
 */
var inorderTraversal = function (root) {
  const answer = [];

  function inorder(root) {
    if (!root) return;

    inorder(root.left);
    answer.push(root.val);
    inorder(root.right);
  }

  inorder(root);
  return answer;
};
๋ฐ˜์‘ํ˜•

'๐Ÿƒ algorithm > leetcode' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

LeetCode 54 - Spiral Matrix (Medium)  (0) 2021.03.03
LeetCode 279 - Perfect Squares (Medium)  (0) 2021.03.03
LeetCode 394 - Decode String (Medium)  (0) 2021.03.03
LeetCode 78 - Subsets (Medium)  (0) 2021.03.03
LeetCode 739 - Daily Temperatures (Medium)  (0) 2021.03.03

๐Ÿ’ฌ ๋Œ“๊ธ€