-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTREE2.java
More file actions
55 lines (47 loc) · 1.39 KB
/
TREE2.java
File metadata and controls
55 lines (47 loc) · 1.39 KB
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
45
46
47
48
49
50
51
52
53
54
55
/* package codechef; // don't place package name! */
import java.util.*;
import java.lang.*;
// import java.math.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
try{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter ot=new PrintWriter(System.out);
int t=Integer.parseInt(br.readLine().trim());
// int total=0;
while(t-->0)
{
int n=Integer.parseInt(br.readLine().trim());
int a[]=new int[n];
String s[]=br.readLine().trim().split(" ");
for(int i=0;i<n;i++)
a[i]=Integer.parseInt(s[i]);
ot.println(find(a,n));
}
ot.close();
br.close();
} catch(Exception e){
System.err.println("ERROR");
return;
}
}
public static int find(int a[],int n){
boolean bool=true;
Set<Integer> set=new HashSet<>();
// int count=n;
for(int i=0;i<n;i++)
{
if(a[i]==0)
bool=false;
set.add(a[i]);
}
if(bool)
return set.size();
return set.size()-1;
}
}