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
相关推荐
迅猛龙办公室1 小时前
python实现倒序输出数字
开发语言·python
夏幻灵9 小时前
LeetCode 21:合并两个有序链表——双指针与哑节点详解
算法·leetcode·链表
全栈练习生11 小时前
AI Agent 沙箱
python·ai
Navigator_Z11 小时前
LeetCode //C - 1286. Iterator for Combination
c语言·算法·leetcode
SEO_juper12 小时前
用 Python 写一个 GEO 可见性检查脚本:你的网站现在能被 AI 引用吗
开发语言·人工智能·爬虫·python·seo·外贸独立站
用户83562907805113 小时前
使用 Python 对 Excel 工作表进行排序
后端·python
圣保罗的大教堂13 小时前
leetcode 301. 删除无效的括号 困难
leetcode
for_ever_love__13 小时前
MySQL 全文索引实战:FULLTEXT、ngram 中文分词与 MATCH AGAINST 到底该怎么用
java·python·mysql·全文检索·分词·索引·ngram
用户83562907805113 小时前
使用 Python 合并 PowerPoint 演示文稿
后端·python
weixin_4617694013 小时前
VS Code 中创建 Jupyter 文件(.ipynb)
ide·python·jupyter