中序便利二元數
中序便利:左子樹 → 根節點 → 右子樹
class Solution {
public:
void DFS(TreeNode* root, vector<int>& ans){
// 終止條件
if(!root) return;
DFS(root->left, ans);
ans.push_back(root->val);
DFS(root->right, ans);
}
vector<int> inorderTraversal(TreeNode* root) {
vector<int> ans;
DFS(root, ans);
return ans;
}
};