// 有序数组去重 时间O(N) 空间O(1)public static int[] removeDuplicate(int[] arr) {if (arr == null || arr.length == 0) {return null;}int slow = 0; // 慢指针 元素不同时才移动int fast = 1; // 快指针while (fast < arr.length) {if (arr[fast] != arr[slow]) { // 快慢指针对应的元素不相等,将快指针位置上的元素赋值slow++slow++;arr[slow] = arr[fast];}fast++;}// 把去重之后的数据重新复制成一个新数组返回return Arrays.copyOfRange(arr, 0, slow + 1);}
