力扣面试150 删除有序数组中的重复项 II 双指针

Problem: 80. 删除有序数组中的重复项 II
在这里插入图片描述

思路

👩‍🏫 三叶题解
在这里插入图片描述

复杂度

时间复杂度: O ( n ) O(n) O(n)

空间复杂度: O ( 1 ) O(1) O(1)

Code

class Solution {
    public int removeDuplicates(int[] nums) {
        int idx = 1; 
        int n = nums.length;
        for(int i = 2; i < n; i++)
        {
            if(nums[i] != nums[idx-1])
                nums[++idx] = nums[i];
        }
        return idx+1;
    }
}

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-28 17:04:05       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-28 17:04:05       101 阅读
  3. 在Django里面运行非项目文件

    2024-03-28 17:04:05       82 阅读
  4. Python语言-面向对象

    2024-03-28 17:04:05       91 阅读

热门阅读

  1. Leetcode 169

    2024-03-28 17:04:05       43 阅读
  2. go加载配置

    2024-03-28 17:04:05       41 阅读
  3. python快速入门一

    2024-03-28 17:04:05       43 阅读
  4. Http和Https

    2024-03-28 17:04:05       41 阅读
  5. 【无标题】

    2024-03-28 17:04:05       38 阅读
  6. Python的json格式处理

    2024-03-28 17:04:05       45 阅读
  7. 2024.3.25每日一题

    2024-03-28 17:04:05       46 阅读
  8. shell中的浮点类型数值如何进行比较运算

    2024-03-28 17:04:05       42 阅读
  9. python将输出保存到txt文档

    2024-03-28 17:04:05       41 阅读
  10. C# 接口 interface

    2024-03-28 17:04:05       44 阅读
  11. 【保姆级讲解Node.js常用的命令】

    2024-03-28 17:04:05       37 阅读