当前位置: 首页 > news >正文

网站建设专用术语网店推广方式

网站建设专用术语,网店推广方式,网站怎样做多语言切换,上海网站建设索王道下拉有时候需要对某一组数组的数据进行判断是否 递增 的场景,比如我在开发一些体育动作场景下,某些肢体动作是需要持续朝着垂直方向向上变化,那么z轴的值是会累增的。同理,逆向考虑,递减就是它的对立面。 下面是查找总结到…

有时候需要对某一组数组的数据进行判断是否 递增 的场景,比如我在开发一些体育动作场景下,某些肢体动作是需要持续朝着垂直方向向上变化,那么z轴的值是会累增的。同理,逆向考虑,递减就是它的对立面。

下面是查找总结到的所有方式,如有补充可以评论区提出。

资料参考来源: Check if list is strictly increasing

1. zip() and all()

  • Code:
test_list = [1, 4, 5, 7, 8, 10]
# Using zip() and all() to
# Check for strictly increasing list
res = all(i < j for i, j in zip(test_list, test_list[1:]))
print(f"Is list strictly increasing ? : {res}")
  • Output:
Is list strictly increasing ? : True

时间复杂度: O(n), n是数组的长度。

2. reduce and lambda

  • Code:
import functoolstest_list = [1, 4, 5, 7, 8, 10]
res = bool((lambda list_demo: functools.reduce(lambda i, j: j ifi < j else 9999, list_demo) != 9999)(test_list))print(f"Is list strictly increasing ? : {res}")
  • Output:
Is list strictly increasing ? : True

时间复杂度: O(n), n是数组的长度。

3. itertools.starmap() + zip() + all()

  • Code:
import itertoolstest_list = [1, 4, 5, 7, 8, 10]
res = all(itertools.starmap(operator.le, zip(test_list, test_list[1:])))print(f"Is list strictly increasing ? : {res}")
  • Output:
Is list strictly increasing ? : True

时间复杂度: O(n), n是数组的长度。

4. sort() and extend()

  • Code:
test_list = [1, 4, 5, 7, 8, 10]
res = False
new_list = []
new_list.extend(test_list)
test_list.sort()if new_list == test_list:res = Trueprint(f"Is list strictly increasing ? : {res}")
  • Output:
Is list strictly increasing ? : True

时间复杂度: O(nlogn), 这里是sort()的时间复杂度

5. Use stacks

栈是一种后进先出的数据结构(Last in, first out)。

  • Code:
def is_strictly_increasing(lst):stack = []for i in lst:if stack and i <= stack[-1]:return Falsestack.append(i)return Truetest_list = [1, 4, 5, 7, 8, 10]
print(is_strictly_increasing(test_list))  # Truetest_list = [1, 4, 5, 7, 7, 10]
print(is_strictly_increasing(test_list))  # False

时间复杂度: O(n),原数组被遍历了一遍
空间复杂度: O(n),栈可能要存储全部的n个原数组元素

6. numpy()

  • Code:
import numpy as npdef is_increasing(lst):# Converting input list to a numpy arrayarr = np.array(lst)# calculate the difference between adjacent elements of the arraydiff = np.diff(arr)# check if all differences are positive# using the np.all() functionis_increasing = np.all(diff > 0)# return the resultreturn is_increasing# Input list
test_list = [1, 4, 5, 7, 8, 10]# Printing original lists
print("Original list : " + str(test_list))result = is_increasing(test_list)print(result)
# True

时间复杂度: O(n)

7. itertools.pairwise() and all()

这里面就等于使用 pairwise() 替代了之前的 zip(list, list[1:])

  • Code:
from itertools import pairwise# Function
def is_strictly_increasing(my_list):# using pairwise method to iterate through the list and# create pairs of adjacent elements.# all() method checks if all pairs of adjacent elements# satisfy the condition i < j, where i and j# are the two elements in the pair.if all(a < b for a, b in pairwise(my_list)):return Trueelse:return False# Initializing list
test_list = [1, 4, 5, 7, 8, 10]# Printing original lists
print("Original list : " + str(test_list))# Checking for strictly increasing list
# using itertools pairwise() and all() method
res = is_strictly_increasing(test_list)# Printing the result
print("Is list strictly increasing ? : " + str(res))
  • Output:
Original list : [1, 4, 5, 7, 8, 10]
Is list strictly increasing ? : True

时间复杂度: O(n)

http://www.mmbaike.com/news/78966.html

相关文章:

  • 腾讯的网站建设用了多少钱搜索引擎推广的方法有
  • php电子商务网站源码中国十大搜索引擎网站
  • wordpress开发的网站有哪些黑科技推广软件
  • 专业做网站的公司哪家好网址提交百度收录
  • 网站建设背景图片百度广告官网
  • 购物网站,购物车界面如何做跨境电商靠谱吗
  • 专业的销售网站软文营销
  • 找公司做网站需要注意什么app拉新推广项目
  • 网站建设如何报价facebook海外推广
  • 网站建设的专业知识国际外贸网络交易平台
  • joomla 1.5 网站建设基础教程如何做百度竞价推广
  • 网站建设的相关技术seo常用工具包括
  • 网站建设流量入口如何做网销
  • 做java一个网站爱站网关键词挖掘查询
  • 肇庆网站开发公司编程培训机构加盟哪家好
  • 呼和浩特市做网站公司好的广州线上教学
  • 有服务器域名源码怎么做网站平台品牌策划包括哪几个方面
  • 专门做英雄联盟h漫的外国网站seo搜索引擎优化论文
  • seo网站推广如何做站长之家seo查找
  • 日本 男女做受视频网站营业推广的方式
  • 宜州做网站需要多少钱市场营销策划案的范文
  • 新疆建设教育协会网站论坛软文案例
  • 建设工程质量检测管理办法沈阳网站关键词优化多少钱
  • 商城网站网络公司seo技术助理
  • 网站设计首页山东做网站公司
  • 自己做的网站如何兼容ie11谷歌优化
  • 如何用wordpress建一个网站分析影响网站排名的因素
  • 美女做暖暖的视频网站中国最新领导班子
  • 社保汇算清缴哪个网站做的网店产品seo如何优化
  • 重庆专门做网站的公司整合营销传播策略