Elegant C++ iterative solution, 0ms, 10 lines
vector<int> preorderTraversal(TreeNode* root) {\n        vector<int> result;\n        stack<TreeNode*> q;\n        q.push(root);\n        while(!q.empty())\n   
    vector<int> preorderTraversal(TreeNode* root) {\n        vector<int> result;\n        stack<TreeNode*> q;\n        q.push(root);\n        while(!q.empty())\n        {\n            auto p = q.top();\n            q.pop();\n            if(p == NULL)\n            {\n                continue;\n            }\n            result.push_back(p->val);\n            q.push(p->right);\n            q.push(p->left);\n        }\n        \n        return result;\n    }
['C++']