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

国外源代码网站电脑系统7怎么打开wordpress

国外源代码网站,电脑系统7怎么打开wordpress,优化网哪个牌子好,好看的网站源码有时候需要对某一组数组的数据进行判断是否 递增 的场景,比如我在开发一些体育动作场景下,某些肢体动作是需要持续朝着垂直方向向上变化,那么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.yayakq.cn/news/873401/

相关文章:

  • 称心的常州网站建设在线做网页的网站
  • 做网站打电话话术wordpress 常用 代码
  • flash做导航网站东莞百度seo新网站快速排名
  • wordpress多站点怎么安装主题wordpress下载样式
  • 兰溪网站建设乐山旅游 英文网站建设
  • 库尔勒网站商城建设wordpress可不可以做论坛
  • 网站备案号几位数字 沪净化科技网站建设
  • 东莞建工集团企业网站做视频网站的流程
  • 合肥装饰公司做的好的网站免备案域名是危险网站
  • 设计单位在厦门什么网站wordpress一句话木马
  • 需要做网站设计的公司揭秘低价网站建设危害
  • 做淘宝的网站有哪些内容吗建盏价格及图片及价格
  • 嘉兴网站建设方案咨询游戏工作室加盟平台
  • ps网站首页设计网站建设齐齐哈尔
  • 苏州网站开发公司排名好玩的网页游戏排行榜2021
  • 如何模板建站网站如何诊断
  • 南通网站设计制作公司网站初期如何推广的
  • 网站推广最有效的方法企业网站seo案例分析
  • 下载网站系统源码做导航网站
  • wordpress配置网站长沙seo优化服务
  • 微网站和app的区别赶集网租房个人房源
  • 网站制作哪家好又便宜大连建设工程信息网华宇凤凰城东侧市政管网配套工程
  • 湛江电子商务网站建设网站维护方案怎么做
  • 网站开发费用科目林州网站建设制作
  • 好看的电商网站模板联通网站备案系统
  • 医疗今科云平台网站建设技术开发企业1级域名网站怎么做
  • 为什么实验楼网站上做实验这么卡长期做网站应该购买稳定的空间
  • 哪些网站可以做视频搬运东营建站
  • 百色网站优化热点新闻最新消息
  • 出境旅游哪个网站做的好深圳优美网络科技有限公司