Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fde0504

Browse files
Add C++ implementation
Signed-off-by: begeekmyfriend <begeekmyfriend@gmail.com>
1 parent e319ebf commit fde0504

File tree

2 files changed

+10
-9
lines changed
  • 1372_longest_zigzag_path_in_a_binary_tree
  • 1373_maximum_sum_bst_in_binary_tree

2 files changed

+10
-9
lines changed

‎1372_longest_zigzag_path_in_a_binary_tree/zigzag.cc‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ class Solution {
3030
int subrzz = 1 + subr.first;
3131
maxzz = max(maxzz, max(sublzz, subrzz));
3232
return make_pair(sublzz, subrzz);
33-
}
33+
}
3434
};

‎1373_maximum_sum_bst_in_binary_tree/max_bst.cc‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ using namespace std;
1313
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
1414
* };
1515
*/
16-
struct TreeInfo {
17-
bool isBst;
18-
int min_val;
19-
int max_val;
20-
int sum_val;
21-
TreeInfo() : isBst(true), min_val(INT_MAX), max_val(INT_MIN), sum_val(0) {}
22-
TreeInfo(bool bst, int min, int max, int sum) : isBst(bst), min_val(min), max_val(max), sum_val(sum) {}
23-
};
2416

2517
class Solution {
2618
public:
@@ -29,6 +21,15 @@ class Solution {
2921
return max(0, max_sum);
3022
}
3123
private:
24+
struct TreeInfo {
25+
bool isBst;
26+
int min_val;
27+
int max_val;
28+
int sum_val;
29+
TreeInfo() : isBst(true), min_val(INT_MAX), max_val(INT_MIN), sum_val(0) {}
30+
TreeInfo(bool bst, int min, int max, int sum) : isBst(bst), min_val(min), max_val(max), sum_val(sum) {}
31+
};
32+
3233
int max_sum = INT_MIN;
3334
TreeInfo *dfs(TreeNode *root) {
3435
if (root == nullptr) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /