forked from alexprut/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Solution.java
37 lines (33 loc) · 941 Bytes
/
Solution.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
static String solve(int[] a, int sum){
String result = "NO";
int left = 0;
int right = sum;
for (int i = 0; i < a.length; i++) {
right -= a[i];
if (i - 1 >= 0) { left += a[i-1]; }
if (right == left) { return "YES"; }
}
return result;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for(int a0 = 0; a0 < T; a0++){
int n = in.nextInt();
int sum = 0;
int[] a = new int[n];
for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
sum += a[a_i];
}
String result = solve(a, sum);
System.out.println(result);
}
}
}