AcWing 817. 数组去重 - Java
原题链接
中等
作者:
KYCygni
,
2021-03-28 11:56:27
,
所有人可见
,
阅读 261
Java 代码
import java.util.Scanner;
public class Main
{
public static int getUniqueCount(int[] nums, int n)
{
int count = 0;
for (int i = 0; i < nums.length; i ++)
{
boolean dup = false;
for (int j = 0; j < i; j ++)
{
if (nums[i] == nums[j])
{
dup = true;
break;
}
}
if (!dup)
count += 1;
}
return count;
}
public static void main(String[] args)
{
Scanner cin = new Scanner(System.in);
int n = cin.nextInt();
int[] nums = new int[n];
for (int i = 0; i < n; i ++)
{
nums[i] = cin.nextInt();
}
System.out.println(getUniqueCount(nums, n));
}
}