mirror of
https://github.com/lWolvesl/leetcode.git
synced 2026-01-13 02:38:37 +08:00
init
This commit is contained in:
34
23/09/Q1123.h
Normal file
34
23/09/Q1123.h
Normal file
@@ -0,0 +1,34 @@
|
||||
//
|
||||
// Created by 李洋 on 2023/9/6.
|
||||
//
|
||||
|
||||
#ifndef LEECODE_C_Q1123_H
|
||||
#define LEECODE_C_Q1123_H
|
||||
#pragma once
|
||||
|
||||
#include "../../dataStruct/Tree/TreeStack.h"
|
||||
|
||||
std::pair<TreeNode *, int> f(TreeNode *root) {
|
||||
if (!root) {
|
||||
return {root, 0};
|
||||
}
|
||||
|
||||
auto left = f(root->left);
|
||||
auto right = f(root->right);
|
||||
|
||||
if (left.second > right.second) {
|
||||
return {left.first, left.second + 1};
|
||||
}
|
||||
if (left.second < right.second) {
|
||||
return {right.first, right.second + 1};
|
||||
}
|
||||
return {root, left.second + 1};
|
||||
|
||||
}
|
||||
|
||||
struct TreeNode *lcaDeepestLeaves(struct TreeNode *root) {
|
||||
return f(root).first;
|
||||
}
|
||||
|
||||
|
||||
#endif //LEECODE_C_Q1123_H
|
||||
Reference in New Issue
Block a user