LeetCode Brush Question 1013. Divide the array into three equal parts
I don't know where I am going, but I am already on my way!
Time is hurried, although I have never met, but I met Yusi, it is really a great fate, thank you for your visit!
Topic : Given an integer array A, only return if we can divide it into three equal non-empty parts true, otherwise return false. Formally, if we can find the index i+1 < jand satisfy (A[0] + A[1] + ... + A[i] == A[i+1] + A[i+2] + ... + A[j-1] == A[j] + A[j-1] + ... + A[A.length - 1])it, we can divide the array into three equal parts.
Algorithm description: First judge whether Athe sum of all elements can be divisible by 3, and return directly False; if it can be divisible, use a double pointer to traverse from the left and right ends to the middle, and find the cumulative sum of the two ends respectively, provided that the middle section can not be empty, i.e., loop condition to be met i < jwhen the third and the accumulated sum of the both ends, respectively, return True, otherwise return loop end False.