博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Remove Duplicates from Sorted Array LeetCode
阅读量:5089 次
发布时间:2019-06-13

本文共 640 字,大约阅读时间需要 2 分钟。

描述

Given a sorted array, remove the duplicates in place such that each element appear only
once and return the new length.
Do not allocate extra space for another array, you must do this in place with constant memory.
For example, Given input array A = [1,1,2],
Your function should return length = 2, and A is now [1,2].
分析
代码 

1 public class solution { 2  3     public static void main(String[] args) { 4          5         int[] A= {1,1,1,2,2,3}; 6         int n = A.length; 7         int index=removeDuplicates(A,n); 8         int[] B=new int[index];//定义好数组长度不好改 9         for(int i=0;i

 

转载于:https://www.cnblogs.com/ncznx/p/9167232.html

你可能感兴趣的文章