Skip to content

Commit 3913060

Browse files
removed unnecessary code
1 parent a3b1359 commit 3913060

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

CS_42_TopViewOfBT.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class TreeNode
1919

2020
vector<int> getTopView(TreeNode<int> *root)
2121
{
22+
// hd means horizontal distance which is nothing but the x-coordinate of the node (or we can say it's a vertical level)
2223
map<int, int> hdToNode;
2324
queue<pair<TreeNode<int> *, int>> q;
2425
q.push({root, 0});
@@ -31,17 +32,17 @@ vector<int> getTopView(TreeNode<int> *root)
3132
int hd = temp.second;
3233

3334
// if no entry for this hd exists, then add it in the map
34-
if (hdToNode.find(hd) == hdToNode.end())
35+
if (!hdToNode[hd])
3536
{
3637
hdToNode[hd] = frontNode->data;
3738
}
3839

3940
// children
40-
if (frontNode->left != NULL)
41+
if (frontNode->left)
4142
{
4243
q.push({frontNode->left, hd - 1});
4344
}
44-
if (frontNode->right != NULL)
45+
if (frontNode->right)
4546
{
4647
q.push({frontNode->right, hd + 1});
4748
}

0 commit comments

Comments
 (0)