반응형
https://leetcode.com/problems/binary-tree-inorder-traversal/
Binary Tree Inorder Traversal - LeetCode
Can you solve this real interview question? Binary Tree Inorder Traversal - Given the root of a binary tree, return the inorder traversal of its nodes' values. Example 1: [https://assets.leetcode.com/uploads/2020/09/15/inorder_1.jpg] Input: root = [1,nu
leetcode.com
중위순회하였습니다.
class Solution {
public:
vector<int> inorderTraversal(TreeNode* root) {
vector<int> res;
inorder(root, res);
return res;
}
void inorder(TreeNode* node, vector<int>& res) {
if(!node) return;
inorder(node->left, res);
res.push_back(node->val);
inorder(node->right, res);
}
};
반응형
'Algorithm' 카테고리의 다른 글
LeetCode 1287. Element Appearing More Than 25% In Sorted Array (0) | 2023.12.12 |
---|---|
LeetCode 867. Transpose Matrix (1) | 2023.12.10 |
LeetCode 606. Construct String from Binary Tree (0) | 2023.12.09 |
LeetCode 1903. Largest Odd Number in String (1) | 2023.12.07 |
LeetCode 1716. Calculate Money in Leetcode Bank (1) | 2023.12.07 |