#1013
Partition Array Into Three Parts With Equal Sum
pupil · 480 · lc easy +27 · verified · 42.6% accepted · 1,790 likes · top 24%
Description
Given an integer array arr, return true if it can be split into three consecutive non-empty parts each having the same sum.
Formally, find indices i + 1 < j such that arr[0] + ... + arr[i] == arr[i+1] + ... + arr[j-1] == arr[j] + ... + arr[arr.length-1].
Example 1:
Input: arr = [0,2,1,-6,6,-7,9,1,2,0,1]
Output: true
Explanation: 0 + 2 + 1 = -6 + 6 - 7 + 9 + 1 = 2 + 0 + 1
Example 2:
Input: arr = [0,2,1,-6,6,7,9,-1,2,0,1]
Output: false
Example 3:
Input: arr = [3,3,6,5,-2,2,5,1,-9,4]
Output: true
Explanation: 3 + 3 = 6 = 5 - 2 + 2 + 5 + 1 - 9 + 4
Code
1
2
3