---
# System prepended metadata

title: 2178. Maximum Split of Positive Even Integers
tags: [Leetcode, Medium, Math, Greedy]

---

# 2178. Maximum Split of Positive Even Integers
###### tags: `Leetcode` `Medium` `Math` `Greedy`
Link: https://leetcode.com/problems/maximum-split-of-positive-even-integers/
## 思路 $O(N)$ $N$为答案长度
贪心算法 从最小的开始放, 假设finalSum=32, 就会按照2,4,6,8,10的顺序放, finalSum会变成30,26,20,12,2,说明还差2就能凑成32, 但是由于2已经出现过了, 不能再放一个2进去，因此加在最后一位数字上，就不会影响结果
## Code
```java=
class Solution {
    public List<Long> maximumEvenSplit(long finalSum) {
        long i = 2;
        LinkedList<Long> ans = new LinkedList<>();
        if(finalSum%2!=0) return ans;
        while(i <= finalSum){
            finalSum -= i;
            ans.add(i);
            i += 2;
        }
        ans.add(finalSum + ans.pollLast());
        return ans;
    }
}
```