Home > front end >  Ask a question about the algorithm of array: judging an array from a certain position after segmenta
Ask a question about the algorithm of array: judging an array from a certain position after segmenta

Time:01-21

to ask a question about the algorithm of array: judging an array from a certain position after segmentation is on both sides of the same?

For example:
[2, 5, 3, 10] [6, 3, 4, 4, 1], [20, 20] equal on both sides after segmentation,
[2, 5, 3, 11] [6, 3, 4, 4, 2] [22, 20] are not equal on both sides after segmentation,
Use an array of slice (start, end) and reduce ((prev, current, the index)=& gt; {return prev + current; }) method, but for how to implement and high performance without thinking, want to consult everybody here, thank you very much!

CodePudding user response:

The first array sum
Again since the first element in circulation with total minus the current element, if reduced to a certain location, just for half of the total, the result of the reduction is divisible; If the result is less than half of the total, then stop circulation, inseparable,
  • Related