第二题有其他解法: const int max_int = 1e9 + 7; int getTreeSum(TreeNode *root) { return func(root) % max_int; } long long func(TreeNode *root) { if (!root->left) return 1; long long left = func(root->left); long long right = func(root->right); return (2 * max(left,right) + 1); }
点赞 2
牛客网
牛客企业服务