MCPcopy Create free account
hub / github.com/Blankj/awesome-java-leetcode / Solution

Class Solution

src/com/blankj/easy/_0026/Solution.java:11–32  ·  view source on GitHub ↗

author: Blankj blog : http://blankj.com time : 2017/04/30 desc :

Source from the content-addressed store, hash-verified

9 * </pre>
10 */
11public class Solution {
12 public int removeDuplicates(int[] nums) {
13 int len = nums.length;
14 if (len <= 1) return len;
15 int tail = 1;
16 for (int i = 1; i < len; ++i) {
17 if (nums[i - 1] != nums[i]) {
18 nums[tail++] = nums[i];
19 }
20 }
21 return tail;
22 }
23
24 public static void main(String[] args) {
25 Solution solution = new Solution();
26 int[] data = new int[]{0, 1, 1, 2, 3, 3, 3};
27 int len = solution.removeDuplicates(data);
28 for (int i = 0; i < len; i++) {
29 System.out.print(data[i] + (i == len - 1 ? "" : ", "));
30 }
31 }
32}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected