保存されている過去のバージョンの一覧

2019年07月14日04時20分43秒

LeetCode Biweekly Contest 4 3問目 - Maximum Average Subtree [1120]

Source

LeetCode Biweekly Contest 4
問題文

問題概要

省略

解法

省略

cLayversion 20190714-1)のコード [C++に変換後]

#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)

ログイン: