Python | Leetcode Python题解之第26题删除有序数组中的重复项

题目:

题解:

python 复制代码
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        if not nums:
            return 0
        
        n = len(nums)
        fast = slow = 1
        while fast < n:
            if nums[fast] != nums[fast - 1]:
                nums[slow] = nums[fast]
                slow += 1
            fast += 1
        
        return slow
相关推荐
Q741_1471 小时前
C++ 分治 归并排序 归并排序VS快速排序 力扣 912. 排序数组 题解 每日一题
c++·算法·leetcode·归并排序·分治
我狸才不是赔钱货3 小时前
Python的“环境之殇”:从Venv到Conda的终极抉择
开发语言·python·conda
程序员爱钓鱼4 小时前
Python编程实战 - 函数与模块化编程 - 参数与返回值
后端·python·ipython
程序员爱钓鱼4 小时前
Python编程实战 - 函数与模块化编程 - 局部变量与全局变量
后端·python·ipython
jiuri_12159 小时前
Docker使用详解:在ARM64嵌入式环境部署Python应用
python·docker·容器
chenchihwen9 小时前
AI代码开发宝库系列:Function Call
人工智能·python·1024程序员节·dashscope
汤姆yu11 小时前
基于python的化妆品销售分析系统
开发语言·python·化妆品销售分析
熬了夜的程序员11 小时前
【LeetCode】89. 格雷编码
算法·leetcode·链表·职场和发展·矩阵
上去我就QWER11 小时前
Python下常用开源库
python·1024程序员节