美文网首页
leetcode-array, since 2022-05-31

leetcode-array, since 2022-05-31

作者: Mc杰夫 | 来源:发表于2022-05-31 20:36 被阅读0次

(2022.05.31 Tues)

    1. Remove Duplicates from Sorted Array (easy)
      array非递减,有重复,返回这个array中独一无二的元素个数,并放在array前面几位。提示:双指针法
class Solution:
    def removeDuplicates(self, nums: List[int]) -> int:
        left = 0
        for right,e in enumerate(nums):
            if nums[left] != e:
                left += 1
                nums[left] = e
        return left+1

类似提醒还有27 remove duplicates

class Solution:
    def removeElement(self, nums: List[int], val: int) -> int:
        left = 0
        for e in nums:
            if e != val:
                nums[left] = e
                left += 1
            else:
                continue
        return left

相关文章

  • leetcode-array, since 2022-05-31

    (2022.05.31 Tues) Remove Duplicates from Sorted Array (ea...

  • Since

    20170802 再也舍不得自己被别人随意的judge

  • Vue3.0 为什么采用 Proxy和definePropert

    [Vue中文社区](javascript:void(0);) 2022-05-31 08:41 发表于北京 Obj...

  • Java String类

    1. String String - Since:JDK1.0 StringBuffer - Since:JDK1...

  • 《既然我与死神擦肩》......Since Death Brus

    《Since Death Brushed Past Me》 《既然我与死神擦肩》 Since Death brus...

  • 'for' 和'since'

    含'for' 和'since'的现在完成进行时 用含现在完成进行时的 for 指在过去开始一直到现在的一段时间。I...

  • Since 1989

    每一个人都会有一段被埋藏在心底,只会是属于自己的故事。 1989_1 > 1989年的秋天,我在对世界一片懵懂的情...

  • Since 1994

    -有些人 描写了在同一个时代背景下,每个人面对这个世界所产生的不同且有趣的心态。 -一个 希望写一首真的可以骗到听...

  • 2022-06-04 因子论实盘记录

    一、交易记录 2022-05-31 8.08 元买入 17600 股唐人神。2022-06-01 8.13 元卖出...

  • git统计代码

    1天: 主要参数 --since=1.day.ago git log --since=1.day.ago --au...

网友评论

      本文标题:leetcode-array, since 2022-05-31

      本文链接:https://www.haomeiwen.com/subject/mxyzprtx.html