Skip to content

Commit fd0564a

Browse files
authored
Update missing-element-in-sorted-array.cpp
1 parent ac4c4ea commit fd0564a

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: C++/missing-element-in-sorted-array.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ class Solution {
55
public:
66
int missingElement(vector<int>& nums, int k) {
77
int left = 0, right = nums.size() - 1;
8-
while (left <= right) {
8+
while (left <= right) { // find the largest right s.t. k > missingCount(nums, x)
99
const auto& mid = left + (right - left) / 2;
10-
if (check(nums, k, mid)) {
10+
if (!check(nums, k, mid)) {
1111
right = mid - 1;
1212
} else {
1313
left = mid + 1;
@@ -22,6 +22,6 @@ class Solution {
2222
}
2323

2424
bool check(const vector<int>& nums, int k, int x) {
25-
return k <= missingCount(nums, x);
25+
return k > missingCount(nums, x);
2626
}
2727
};

0 commit comments

Comments
 (0)