Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
868 B
21
Indexable
Never
public class Solution {
    public int solve(ArrayList<Integer> A) {
		int count = 0;

		int n = A.size();

		if (n <= 2) {
			return 0;
		}
		ArrayList<Long> evenPS = new ArrayList<>();
		ArrayList<Long> oddPS = new ArrayList<>();

		evenPS.add(Long.valueOf(A.get(0)));
		oddPS.add(0L);

		for (int i = 1; i < n; i++) {
			if (i % 2 == 0) {
				evenPS.add(Long.valueOf(A.get(i)) + evenPS.get(i - 1));
				oddPS.add(oddPS.get(i - 1));
			} else {
				oddPS.add(Long.valueOf(A.get(i)) + oddPS.get(i - 1));
				evenPS.add(evenPS.get(i - 1));
			}
		}

		if (evenPS.get(n - 1) - A.get(0) == oddPS.get(n - 1)) {
			count++;
		}

		for (int i = 1; i < n; i++) {

			if (evenPS.get(i - 1) + oddPS.get(n - 1) - oddPS.get(i) == oddPS.get(i - 1) + evenPS.get(n - 1)
					- evenPS.get(i)) {
				count++;
			}

		}

		return count;
    }
}