Skip to content

Commit 0cf58dc

Browse files
committed
Clean.
1 parent 4f970b0 commit 0cf58dc

File tree

1 file changed

+0
-42
lines changed

1 file changed

+0
-42
lines changed

cpp-leetcode/test.cpp

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,6 @@
1-
#include<queue>
21
#include<vector>
32
#include<algorithm>
43
#include<iostream>
54
using namespace std;
65

7-
/**
8-
* Definition for a binary tree baseTopNode.
9-
*/
10-
struct TreeNode {
11-
int val;
12-
TreeNode *left;
13-
TreeNode *right;
14-
TreeNode() : val(0), left(nullptr), right(nullptr) {}
15-
TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
16-
TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
17-
};
186

19-
class Solution {
20-
public:
21-
int widthOfBinaryTree(TreeNode* root) {
22-
if (!root) return 0;
23-
queue<pair<TreeNode*, int>> q;
24-
q.push({root, 1});
25-
int res = -1;
26-
while (!q.empty())
27-
{
28-
int size = q.size();
29-
int baseTopNo = q.front().second;
30-
int curTopNo;
31-
32-
for (int i = 0; i < size; i++)
33-
{
34-
auto topKvp = q.front();
35-
q.pop();
36-
auto topNode = topKvp.first;
37-
curTopNo = topKvp.second;
38-
auto p = curTopNo - baseTopNo + 1;
39-
if (topNode->left)
40-
q.push({topNode->left, p * 2});
41-
if (topNode->right)
42-
q.push({topNode->right, p * 2 + 1});
43-
}
44-
res = max(res, curTopNo - baseTopNo + 1);
45-
}
46-
return res;
47-
}
48-
};

0 commit comments

Comments
 (0)