Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f02c944

Browse files
committedSep 16, 2015
Update closest-binary-search-tree-value-ii.cpp
1 parent e14c4fc commit f02c944

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed
 

‎C++/closest-binary-search-tree-value-ii.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ class Solution {
3535
// Get the closest k values by advancing the iterators of the stacks.
3636
vector<int> result;
3737
for (int i = 0; i < k; ++i) {
38-
if (backward_stack.empty() ||
39-
(!forward_stack.empty() && closest(forward_stack.back(), backward_stack.back()))) {
38+
if (!forward_stack.empty() &&
39+
(backward_stack.empty() || closest(forward_stack.back(), backward_stack.back()))) {
4040
result.emplace_back(forward_stack.back()->val);
4141
nextNode(forward_stack, forward, backward);
42-
} else if (forward_stack.empty() ||
43-
(!backward_stack.empty() && !closest(forward_stack.back(), backward_stack.back()))) {
42+
} else if (!backward_stack.empty() &&
43+
(forward_stack.empty() || !closest(forward_stack.back(), backward_stack.back()))) {
4444
result.emplace_back(backward_stack.back()->val);
4545
nextNode(backward_stack, backward, forward);
4646
}

0 commit comments

Comments
 (0)
Please sign in to comment.