mirror of
https://github.com/arkorty/LeetCode.git
synced 2026-03-18 00:57:17 +00:00
Refactor some stuff
This commit is contained in:
@@ -6,14 +6,12 @@ struct TreeNode {
|
|||||||
TreeNode *right;
|
TreeNode *right;
|
||||||
TreeNode() : val(0), left(nullptr), right(nullptr) {}
|
TreeNode() : val(0), left(nullptr), right(nullptr) {}
|
||||||
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
|
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
|
||||||
TreeNode(int x, TreeNode *left, TreeNode *right)
|
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
|
||||||
: val(x), left(left), right(right) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Solution {
|
class Solution {
|
||||||
private:
|
private:
|
||||||
void levelOrder(std::vector<std::vector<int>> &levels, TreeNode *root,
|
void levelOrder(std::vector<std::vector<int>> &levels, TreeNode *root, int index) {
|
||||||
int index) {
|
|
||||||
if (root == nullptr) {
|
if (root == nullptr) {
|
||||||
return;
|
return;
|
||||||
} else if (levels.size() == index) {
|
} else if (levels.size() == index) {
|
||||||
@@ -25,7 +23,7 @@ class Solution {
|
|||||||
levelOrder(levels, root->right, index + 1);
|
levelOrder(levels, root->right, index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::vector<std::vector<int>> levelOrder(TreeNode *root) {
|
std::vector<std::vector<int>> levelOrder(TreeNode *root) {
|
||||||
std::vector<std::vector<int>> levels;
|
std::vector<std::vector<int>> levels;
|
||||||
levelOrder(levels, root, 0);
|
levelOrder(levels, root, 0);
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ public:
|
|||||||
int maxArea = 0;
|
int maxArea = 0;
|
||||||
int curArea = 0;
|
int curArea = 0;
|
||||||
while (left < right) {
|
while (left < right) {
|
||||||
curArea =
|
curArea = (right - left) * (height[left] < height[right] ? height[left] : height[right]);
|
||||||
(right - left) *
|
|
||||||
(height[left] < height[right] ? height[left] : height[right]);
|
|
||||||
maxArea = maxArea > curArea ? maxArea : curArea;
|
maxArea = maxArea > curArea ? maxArea : curArea;
|
||||||
|
|
||||||
if (height[left] > height[right]) {
|
if (height[left] > height[right]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user