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