-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSherlockAndArray.java
More file actions
44 lines (38 loc) · 892 Bytes
/
SherlockAndArray.java
File metadata and controls
44 lines (38 loc) · 892 Bytes
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
38
39
40
41
42
43
44
import java.util.*;
public class SherlockAndArray
{
public static boolean isEven(int[] arr)
{
if (arr.length == 0)
{
return false;
}
int difference = arr[0] - Arrays.stream(arr).sum();
if (difference == 0) {
return true;
}
for (int i = 1; i < arr.length; i++) {
difference += arr[i-1];
difference += arr[i];
if (difference == 0) {
return true;
}
}
return false;
}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i=0 ; i<t ; i++)
{
int n = in.nextInt();
int[] arr = new int[n];
for(int j=0 ; j<n ; j++)
{
arr[j]=in.nextInt();
}
System.out.println(isEven(arr) ? "YES" : "NO");
}
}
}