Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- object Solution {
- def solution(A: Array[Int]): Int = {
- def recurse(smallestResult: Int, headSum: Int, tailSum: Int, restOfList: List[Int]): Int = {
- if(restOfList.isEmpty) smallestResult
- else recurse(math.min((headSum - tailSum).abs,smallestResult),headSum + restOfList.head,tailSum - restOfList.head,restOfList.tail)
- }
- val initialTailSum = A.tail.sum
- recurse((A.head - initialTailSum).abs, A.head, initialTailSum, A.tail.toList)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement