LeetCode Biweekly Contest 4
問題文
省略
省略
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S chmax(S &a, T b){
if(a<b){
a=b;
}
return a;
}
double res;
pair<double, int> solve(TreeNode* root){
pair<double, int> r, t1, t2;
if(root==NULL){
return make_pair(0.0, 0);
}
t1 = solve(root->left);
t2 = solve(root->right);
r.first = t1.first + t2.first + root->val;
r.second = t1.second + t2.second + 1;
chmax(res, r.first / r.second);
return r;
}
class Solution{
public:
double maximumAverageSubtree(TreeNode* root){
res = -1;
solve(root);
return res;
}
}
;
// cLay varsion 20190714-1
// --- original code ---
// struct TreeNode {};
//
// double res;
//
// pair<double, int> solve(TreeNode* root){
// pair<double, int> r, t1, t2;
//
// if(root==NULL) return make_pair(0.0, 0);
//
// t1 = solve(root->left);
// t2 = solve(root->right);
//
// r.first = t1.first + t2.first + root->val;
// r.second = t1.second + t2.second + 1;
//
// res >?= r.first / r.second;
// return r;
// }
//
// class Solution {
// public:
// double maximumAverageSubtree(TreeNode* root) {
// res = -1;
// solve(root);
// return res;
// }
// };
//
// {
// // main関数を適当に処理する
// }
Current time: 2024年04月30日11時35分56秒
Last modified: 2019年07月14日04時20分43秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る
Logged in as: unknown user (not login)