# Leetcode 94. Binary Tree Inorder Traversal (EASY) ## 題目 [leetcode](https://leetcode.com/problems/binary-tree-inorder-traversal/) ## 思路 這個題目就是最基本ㄉ Inorder Traversal,只要知道最重要ㄉ是先去看左邊再看中間最後再看右邊就可以寫出來ㄌ  img Source:(https://www.shubo.io/iterative-binary-tree-traversal/) ```c++= class Solution { public: vector<int> inorderTraversal(TreeNode* root) { vector<int> v; if (root==nullptr) {return v;} else { inorderTraverse(root, v); } return v; } void inorderTraverse(TreeNode* node, vector<int>& v) { if(node->left != nullptr) { inorderTraverse(node->left,v); } v.emplace_back(node->val); if(node->right != nullptr) { inorderTraverse(node->right, v); } } }; ``` ### 解法分析 + time complexity: O(lgn) ### 執行結果  ## follow up: > Could you .... ```C++= ``` ### 解法分析 + time complexity: O(nlgn) ### 執行結果
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up