zoukankan      html  css  js  c++  java
  • Remove Duplicates from Sorted Array

    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].

    public class Solution {
        public int removeDuplicates(int[] A) {
            int size = A.length;
            int point = 0;
            int temp = Integer.MAX_VALUE;
            for(int i=0;i<size;i++){
                if(A[i]!=temp){
                    temp = A[i];
                    A[point] = A[i];
                    point++;
                }
            }
            return point;
        }
    }
  • 相关阅读:
    WiFi热点
    计算器
    flask的使用
    Python logging
    串口
    C# 定时器
    C# 控件
    cookie 和 session
    文件
    Linux命令
  • 原文地址:https://www.cnblogs.com/mrpod2g/p/4265541.html
Copyright © 2011-2022 走看看