Skip to content

Commit f9442eb

Browse files
authored
Update the-k-weakest-rows-in-a-matrix.cpp
1 parent b76137d commit f9442eb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

C++/the-k-weakest-rows-in-a-matrix.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Solution {
1313
}
1414
lookup.emplace(i);
1515
result.emplace_back(i);
16-
if (!--k) {
16+
if (result.size() == k) {
1717
return result;
1818
}
1919
}
@@ -24,7 +24,7 @@ class Solution {
2424
}
2525
lookup.emplace(i);
2626
result.emplace_back(i);
27-
if (!--k) {
27+
if (result.size() == k) {
2828
break;
2929
}
3030
}
@@ -44,7 +44,7 @@ class Solution2 {
4444
continue;
4545
}
4646
lookup[i] = true;
47-
if (!--k) {
47+
if (lookup.size() == k) {
4848
return lookup.keys();
4949
}
5050
}
@@ -54,7 +54,7 @@ class Solution2 {
5454
continue;
5555
}
5656
lookup[i] = true;
57-
if (!--k) {
57+
if (lookup.size() == k) {
5858
break;
5959
}
6060
}
@@ -91,6 +91,10 @@ class Solution2 {
9191
});
9292
return result;
9393
}
94+
95+
int size() const {
96+
return list_.size();
97+
}
9498

9599
private:
96100
list<pair<K, V>> list_;

0 commit comments

Comments
 (0)