2024.5.6 —— LeetCode 高频题复盘

283. 移动零


题目链接

Python

class Solution:
    def moveZeroes(self, nums: List[int]) -> None:
        """
        Do not return anything, modify nums in-place instead.
        """
        n=len(nums)
        i=0
        for j in range(n):
            if nums[j]!=0:
                nums[i],nums[j]=nums[j],nums[i]
                i+=1 # i指向0,因为当前数字不为0才前进

153. 寻找旋转排序数组中的最小值


题目链接

Python

class Solution:
    def findMin(self, nums: List[int]) -> int:
        low,high=0,len(nums)-1
        while low<high:
            mid=(low+high)//2
            # 元素值互不相同
            if nums[mid]<nums[high]:
                high=mid
            else: # nums[mid]>nums[high]:
                low=mid+1
        return nums[low]

类似题目 33. 搜索旋转排序数组

468. 验证IP地址


题目链接

Python

class Solution:
    def validIPAddress(self, queryIP: str) -> str:

        def validIPv6(IP_string):
            IP_lst = IP_string.split(':')
            if len(IP_lst) != 8: # IPv6必须由8个子串组成
                return False
            for IP in IP_lst:
                if not 1 <= len(IP) <= 4: # 每个子串必须小于4个字符
                    return False
                for char in IP:
                    if not ('0' <= char <= '9' or 'a' <= char <= 'f' or 'A' <= char 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值