2019年07月14日13時59分56秒に更新されたバージョンを表示しています.
最新のページはこちらをご覧ください.
LeetCode Weekly Contest 145
問題文
省略
省略
#include<bits/stdc++.h>
using namespace std;
pair<int, TreeNode*> solve(TreeNode *root){
pair<int, TreeNode*> t1, t2;
if(root==NULL){
return make_pair(0, root);
}
t1 = solve(root->left);
t2 = solve(root->right);
if(t1.first > t2.first){
t1.first++;
return t1;
}
if(t1.first < t2.first){
t2.first++;
return t2;
}
return make_pair(t1.first+1, root);
}
class Solution{
public:
TreeNode* lcaDeepestLeaves(TreeNode* root){
pair<int, TreeNode*> res;
res = solve(root);
return res.second;
}
}
;
// cLay varsion 20190714-1
// --- original code ---
// struct TreeNode{
// int val;
// TreeNode *left, *right;
// };
//
// pair<int, TreeNode*> solve(TreeNode *root){
// pair<int, TreeNode*> t1, t2;
//
// if(root==NULL){
// return make_pair(0, root);
// }
//
// t1 = solve(root->left);
// t2 = solve(root->right);
//
// if(t1.first > t2.first){
// t1.first++;
// return t1;
// }
// if(t1.first < t2.first){
// t2.first++;
// return t2;
// }
//
// return make_pair(t1.first+1, root);
// }
//
// class Solution {
// public:
// TreeNode* lcaDeepestLeaves(TreeNode* root) {
// pair<int, TreeNode*> res;
// res = solve(root);
// return res.second;
// }
// };
//
// {
// // main関数を適当に処理する
// }
Current time: 2024年05月21日21時57分05秒
Last modified: 2019年07月14日13時59分56秒 (by laycrs)
Tags: Competitive_Programming_Incomplete LeetCode
トップページに戻る
Logged in as: unknown user (not login)