2021-03-14

628.三个数的最大乘积

分析讨论各种情况,可以知道,最大乘积要么是前三个数的乘积,要么是第一个数和最后两个数的乘积。

class Solution(object):
    def maximumProduct(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        # 如果一共只有三个数
        # prod=1
        if(len(nums)==3):
            return nums[0]*nums[1]*nums[2]
        else:
            # 排序,降序
            nums.sort(reverse=True)
            prod1=nums[0]*nums[1]*nums[2]
            prod2=nums[0]*nums[-1]*nums[-2]
            return max(prod1,prod2)

            

1550. 存在连续三个奇数的数组

简单地直接判断即可

class Solution(object):
    def threeConsecutiveOdds(self, arr):
        """
        :type arr: List[int]
        :rtype: bool
        """
        flag=False
        i=0
        while(i<len(arr)-2):
            if(arr[i]%2==0):
                i=i+1
                continue
            elif(arr[i+1]%2==0):
                i=i+2
                continue
            elif(arr[i+2]%2==0):
                i=i+3
                continue
            else:
                return True
        return False


219. 存在重复元素

用字典存储元素及其下标

class Solution(object):
    def containsNearbyDuplicate(self, nums, k):
        """
        :type nums: List[int]
        :type k: int
        :rtype: bool
        """
        dct={}
        for i in range(len(nums)):
            if(nums[i] in dct and dct[nums[i]]>=(i-k)):
                return True
            dct[nums[i]]=i
        return False

228. 汇总区间

class Solution(object):
    def summaryRanges(self, nums):
        """
        :type nums: List[int]
        :rtype: List[str]
        """
        # 这个数组是有序的
        ret=[]
        i=0
        while(i<len(nums)):
            sub=""
            sub=sub+str(nums[i])
            j=i+1
            while(j<len(nums) and (j-i)==(nums[j]-nums[i])):
                j=j+1
            if(j-1>i):
                sub=sub+"->"
                sub=sub+str(nums[j-1])
                # ret.append(str(j-1))
            i=j
            ret.append(sub)
        return ret

数据接口:https://api.getweapp.com/vendor/lightstao/searchkeyhttps://api.getweapp.com/vendor/lightstao/product/search微信小程序中,懒加载特效让人头疼不已,因为小程序完全没法操作dom,所以位置的操作在小程序中,变得极其的难~~先看特效:我们将其拆分为如下几个步骤进行讲解~~1)如何获取图片的位置高度先看一张图:通过上图可以知道,图片位置高度其实可以通过img.height margin值算出。js代码:arrHight[i] = Math.floor(i/2)*(img.height   margin-bottom);为何是Math.floor(i/2)呢,因为同一排两张图片高度一样,比如i=0和i=1,通过Math.floor得出值都为0,所以可以保证同一排的两张图片位置高度是同一个值。2)替换默认图片先看效果图片:wxml代码:<image src="{{arr[index] ? productArr[index].Image : 'default.jpg'}}"></image>思路很明显,一开始arr[index]中都是false,所以默认都是default图片但是随着往下移动,有些arr[index]的值变为true,所以替换默认图片js代码:for (var i = 0; i < this.data.productArr.length; i ) {   if (arrHight[i] < scrollTop) {       if (arr[i] == false) {           arr[i] = true;       }   } }思路相当清晰,无需多言~~3)懒加载中渐显特效先看效果:wxss代码:.product_image{   opacity: 0;   width: 100%;   height: 70%;   transition: opacity 1s linear 2s; } .loaded{     opacity: 1; }其实就是opacity的一个过渡动画而已,so easy~~作者:小小小是我
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值