C++ Solution | Clean code
\n# Complexity\n- Time complexity: 0 ms (100%)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: 13.6 MB (6.52%)\n Add your space complexity he
\n# Complexity\n- Time complexity: 0 ms (100%)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: 13.6 MB (6.52%)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     TreeNode() : val(0), left(nullptr), right(nullptr) {}\n *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}\n *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}\n * };\n */\nclass Solution {\npublic:\n    void levelOrder(TreeNode* root, int level, vector<vector<int>> &answer)\n    {\n        if(!root)\n            return;\n        if(level == answer.size())\n            answer.push_back({root->val});\n        else\n            answer[level].push_back(root->val);\n        levelOrder(root->left , level+1, answer);\n        levelOrder(root->right, level+1, answer);\n    }\n    vector<vector<int>> levelOrder(TreeNode* root) {\n        vector<vector<int>> ans;\n        levelOrder(root, 0, ans);\n        return ans;\n    }\n};\n```
['Recursion', 'C++']