# Remove Duplicated

Given an array of integers, remove the duplicate numbers in it.

You should:

1. Do it in place in the array.
2. Move the unique numbers to the front of the array.
3. Return the total number of the unique numbers.

## Example

Given*nums*=`[1,3,1,4,4,2]`, you should:

1. Move duplicate integers to the tail of *nums*=>*nums*=`[1,3,4,2,?,?]`.
2. Return the number of unique integers in *nums*=>`4`.

Actually we don't care about what you place in`?`, we only care about the part which has no duplicate integers.

## Note

要先排序的。右指针遍历，左指针来判断特殊情况

一般都操作不一样的，把右指针的数换到左指针的后一位，如果所有数字都是不一样的左指针会一直比右指针慢一格，右指针会和自己换，所以也是work的。

所以最后返回就是左指针的位置加一

## Code

```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
        /*
        [1,  2,  3,  4,  3,  4,  4]
                     l
                                  r
        */
        if (nums == null || nums.length == 0) {
            return 0;
        }
        Arrays.sort(nums);
        int l = 0, r = 0;
        while (r < nums.length) {
            if (nums[r] != nums[l]) {
                l++;
                nums[l] = nums[r];
            }
            r++;
        }
        return l + 1;
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://luj.gitbook.io/code/two-pointers/1-forward/remove-duplicated.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
