#108. 数组分割求和
数组分割求和
Array Split Sum
Background
Congcong is playing a number game. He has an array of integers and wants to know if he can split this array into two parts such that the sum of numbers in both parts is equal.
Problem Description
Given a non-empty array of integers, return true if there is a place to split the array so that the sum of the numbers on one side is equal to the sum of the numbers on the other side. Otherwise, return false.
Input Format
Input is given from standard input in the following format.
A non-empty array of integers, with elements separated by spaces.
Output Format
Output is printed to standard output in the following format.
Output
trueif such a split point exists; otherwise, outputfalse.
Sample
[1 1 1 2 1]
true
[2 1 1 2 1]
false
[10 10]
true
Sample Explanation
Sample 1: The array is [1 1 1 2 1]. The total sum is . It can be split after the third , resulting in [1 1 1] and [2 1]. Both parts sum to . Thus, return true.
Sample 2: The array is [2 1 1 2 1]. The total sum is . No split point can make both parts sum equally. Thus, return false.
Sample 3: The array is [10 10]. The total sum is . It can be split after the first , resulting in [10] and [10]. Both parts sum to . Thus, return true.
Constraints
Time limit for each test case is second, memory limit is KiB.