https://leetcode.com/problems/binary-tree-inorder-traversal/description
Q. 주어진 tree를 inorder로 순회하고 그 값을 반환하라.
Solution.
Binary Tree의 기본기.
가급적 풀 줄 알아야 하겠다.
void inorderTraverseBT(vector<int>& vOut, TreeNode* node)
{
if (node == NULL) return;
inorderTraverseBT(vOut, node->left);
vOut.push_back(node->val);
inorderTraverseBT(vOut, node->right);
}
vector<int> inorderTraversal(TreeNode* root)
{
vector<int> vRet;
inorderTraverseBT(vRet, root);
return vRet;
}
결과.
'Leetcode > Top 100 Liked' 카테고리의 다른 글
[Binary Tree][Easy] 101. Symmetric Tree (0) | 2024.03.09 |
---|---|
[Binary Tree][Medium] 98. Validate Binary Search Tree (0) | 2024.03.09 |
[Binary Search][Medium] 153. Find Minimum in Rotated Sorted Array (0) | 2024.03.08 |
[Binary Search][Hard] 124. Binary Tree Maximum Path Sum (0) | 2024.03.07 |
[Binary Search][Medium] 74. Search a 2D Matrix (1) | 2024.03.06 |