Solution in C++
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\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 \n{\npublic:\n    TreeNode* lowestCommonAncestor(TreeNode* root, TreeNode* p, TreeNode* q) {\n        if (!root) return NULL;\n        if (root==p || root==q) return root;\n        TreeNode *l = lowestCommonAncestor(root->left,p,q);\n        TreeNode *r = lowestCommonAncestor(root->right,p,q);\n        if (l&&r) return root;\n        if (l) return l;\n        return r;\n    } \n    vector<vector<TreeNode*>> bfs(TreeNode* root)\n     {\n        vector<vector<TreeNode*>> ret;\n        queue<TreeNode*> q;\n        q.push(root);\n        while(!q.empty()) {\n            int currlen = q.size();\n            vector<TreeNode*> row;\n            for (int i=0; i<currlen; i++) {\n                auto curr = q.front(); q.pop();\n                row.push_back(curr);\n                if (curr->left) q.push(curr->left);\n                if (curr->right) q.push(curr->right);\n            }\n            ret.push_back(row);\n        }\n        return ret;\n    }\n    TreeNode* subtreeWithAllDeepest(TreeNode* root)\n     {\n        vector<vector<TreeNode*>> level = bfs(root);\n        vector<TreeNode*> tmp = level.back();\n        if (tmp.size()==1) return tmp[0];\n        return lowestCommonAncestor(root, tmp[0], tmp.back());\n    }\n};\n```
['C++']