> For the complete documentation index, see [llms.txt](https://shangan.gitbook.io/algorithm/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://shangan.gitbook.io/algorithm/he-xin-suan-fa-200-ti/untitled/remove-duplicate-numbers-in-array.md).

# Remove Duplicate Numbers in Array

{% tabs %}
{% tab title="Java" %}

```java
public class Solution {
    /**
     * @param nums an array of integers
     * @return the number of unique integers
     */
    public int deduplication(int[] nums) {
        // Write your code here
        if (nums.length == 0) {
            return 0;
        }
        
        Arrays.sort(nums);
        int i, j = -1;
        for (i = 0; i < nums.length; ++i) {
            if (j == -1 || nums[i] != nums[j]) {
                ++j;
                nums[j] = nums[i];
            }
        }
        
        return j + 1;
    }
}
```

{% endtab %}
{% endtabs %}

![](https://2784211123-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M-ELB26IpzCEJWSDi0m%2F-M-ELbsic2B8wwsarT-C%2F-M-EMqc6UhBUlpM3zyHy%2F1580805867266.jpg?alt=media\&token=11a20b67-9e32-4c02-bf02-c405dac8ef0f)
