8 lines cpp solution.(recursive)


  • 0
    J
    class Solution {
    public:
        vector<int> ans;
        vector<int> inorderTraversal(TreeNode* root) {
            if (root!=nullptr) {
            inorderTraversal(root->left);   //left
            ans.push_back(root->val);       //current
            inorderTraversal(root->right);  //right
            }
            return ans;
        }
    };

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.