Skip to content

Commit 869784e

Browse files
authored
Create 2178-maximum-split-of-positive-even-integers.js
1 parent 7697690 commit 869784e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @param {number} finalSum
3+
* @return {number[]}
4+
*/
5+
const maximumEvenSplit = function(finalSum) {
6+
if(finalSum % 2 === 1) return []
7+
const res = []
8+
let i = 2
9+
while(i <= finalSum) {
10+
res.push(i)
11+
finalSum -= i
12+
i += 2
13+
}
14+
15+
const last = res.pop()
16+
res.push(finalSum + last)
17+
return res
18+
};

0 commit comments

Comments
 (0)