vector<int> inorderTraversal(TreeNode* root) { vector<int> inorderTraversalElems; function<void(TreeNode*& node)> traversal; traversal = [&](TreeNode*& node) { if (node == nullptr) { return; } traversal(node->left); inorderTraversalElems.push_back(node->val); traversal(node->right); }; traversal(root); return inorderTraversalElems; }
时间: 2024-10-25 10:40:26