[C++][Find perfect tree size with DFS]
\n\n# Code\ncpp []\n/**\n * Definition for a binary tree node.\n * struct TreeNode {\n *     int val;\n *     TreeNode *left;\n *     TreeNode *right;\n *     T
\n\n# Code\n```cpp []\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    int kthLargestPerfectSubtreeInternal(TreeNode* root, vector<int>& treeScore){\n        if (!root) return 0;\n        auto left = kthLargestPerfectSubtreeInternal(root->left, treeScore);\n        auto right = kthLargestPerfectSubtreeInternal(root->right, treeScore);\n        if (left==right && left!=-1) {\n            treeScore.push_back(left+right+1);\n            return treeScore.back();\n        }\n        return -1;\n\n    }\npublic:\n    int kthLargestPerfectSubtree(TreeNode* root, int k) {\n        vector<int> treeScore;\n        int _ = kthLargestPerfectSubtreeInternal(root,treeScore);\n        if (treeScore.size()<k) return -1;\n        nth_element(treeScore.begin(),treeScore.begin()+k-1,treeScore.end(),greater());\n        return treeScore[k-1];\n    }\n};\n```
['C++']