Skip to content

Commit b4f38ad

Browse files
committed
1798
1 parent fa4233e commit b4f38ad

File tree

1 file changed

+6
-6
lines changed
  • leetcode/1798. Maximum Number of Consecutive Values You Can Make

1 file changed

+6
-6
lines changed

leetcode/1798. Maximum Number of Consecutive Values You Can Make/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ You can make 8 consecutive integer values starting from 0.</pre>
6262
class Solution {
6363
public:
6464
int getMaximumConsecutive(vector<int>& A) {
65-
int mx = 1;
65+
int cnt = 1;
6666
sort(begin(A), end(A));
6767
for (int n : A) {
68-
if (n > mx) break;
69-
mx += n;
68+
if (n > cnt) break;
69+
cnt += n;
7070
}
71-
return mx;
71+
return cnt;
7272
}
7373
};
7474
```
@@ -106,6 +106,6 @@ If we represent the numbers using binary mask, then `1, 2, 3` is `111`, and `1,
106106

107107
Since we only care about the first number that we can't form, we only need to keep track of the maximum number we can form.
108108

109-
Assume we can form `[0, mx]` numbers and now we get a new number `k`, then we can form `[k, mx + k]` numbers. As long as `k <= mx + 1`, we can extend the range to `[0, mx + k]`.
109+
Assume we can form `[0, cnt)` numbers and now we get a new number `k`, then we can form `[k, cnt + k)` numbers. As long as `k <= cnt`, we can extend the range to `[0, cnt + k)`.
110110

111-
When `k > mx + 1`, we get a gap at `mx + 1`, and thus we can only get `mx + 1` consecutive numbers
111+
When `k > cnt`, we can't form value `cnt`, and thus we can only get `cnt` consecutive numbers

0 commit comments

Comments
 (0)