leetcode(리트코드)94-Binary Tree Inorder Traversal
leetcode(리트코드)94-Binary Tree Inorder Traversal
leetcode 94 - Binary Tree Inorder Traversal 문제입니다.
1. 문제
https://leetcode.com/problems/binary-tree-inorder-traversal/
2. Input , Output
3. 분류 및 난이도
Medium 난이도 문제입니다.
leetcode Top 100 Liked의 문제입니다.
4. 문제 해석
- 특별할 게 없는 Inorder 문제입니다.
5. code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
vector<int> result;
vector<int> inorderTraversal(TreeNode* root) {
if(root!=nullptr)
{
inorderTraversal(root->left);
result.push_back(root->val);
inorderTraversal(root->right);
}
return result;
}
};
6. 결과 및 후기, 개선점
시간(100%)
This post is licensed under CC BY 4.0 by the author.