Skip to content

Commit 62a6e73

Browse files
authored
Update 1798-maximum-number-of-consecutive-values-you-can-make.js
1 parent 338cd2c commit 62a6e73

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

1798-maximum-number-of-consecutive-values-you-can-make.js

+23
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,26 @@ const getMaximumConsecutive = function(coins) {
1111
}
1212
return res;
1313
};
14+
15+
// another
16+
17+
/**
18+
* @param {number[]} coins
19+
* @return {number}
20+
*/
21+
const getMaximumConsecutive = function(coins) {
22+
coins.sort((a, b) => a - b)
23+
let sum = 1, res = 1, i = 0
24+
while(true) {
25+
const e = coins[i]
26+
if(i >= coins.length) break
27+
if(e <= sum) {
28+
sum += e
29+
i++
30+
} else {
31+
break
32+
}
33+
}
34+
35+
return sum
36+
};

0 commit comments

Comments
 (0)