The guy who wrote the fastest solution is a goddamn genius with an IQ of 160!


#1

my sol:-

vector<int> Solution::preorderTraversal(TreeNode* A) {
    stack<TreeNode*>s;
    s.push(A);
    vector<int>ans;
    while(!s.empty())
    {
        TreeNode *temp=s.top();
        s.pop();
        while(temp)
        {
            ans.push_back(temp->val);
            if(temp->right)
            {
                s.push(temp->right);
            }
            temp=temp->left;
        }
    }
    return ans;
}

#2

haha, I thought you were being real until I saw the solution