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

推荐常州模板网站建设新手运营从哪开始学

推荐常州模板网站建设,新手运营从哪开始学,乐清网站开发公司,导入视频生成3d动画目录 1. 循环随机取数组直到得出指定数字? 2. 旋转链表 3. 区间和的个数 1. 循环随机取数组直到得出指定数字? 举个例子: 随机数字范围:0~100 每组数字量:6(s1,s2,s3,s4,s5,s6) 第二轮开始随…

目录

1. 循环随机取数组直到得出指定数字?

2. 旋转链表

3. 区间和的个数


1. 循环随机取数组直到得出指定数字?

举个例子: 随机数字范围:0~100 每组数字量:6(s1,s2,s3,s4,s5,s6) 第二轮开始随机数字范围:新s1和新s2取值为旧s1和s2之间,新s3和新s4取值为旧s3和s4之间,新s5和新s6取值为旧s5和s6之间。 跳出循环条件:任意数字=37 如因s1=s2!=37&&s3=s4!=37&&s5=s6!=37使数组进入无意义无限循环,则重新取0~100六个数字并开始如上述第二轮随机的随机取值。

代码: 

import randomdef random_test():rst_list = [random.randint(0,100) for i in range(0, 6)]print(rst_list)while 1:temp = []for k,v in enumerate(rst_list):if k%2==0:temp.append(random.randint(min([rst_list[k],rst_list[k+1]]),max([rst_list[k],rst_list[k+1]])))else:temp.append(random.randint(min(rst_list[k-1], rst_list[k]),max(rst_list[k-1], rst_list[k])))rst_list = tempprint(rst_list)if 37 in rst_list:print("rst_list:",rst_list)return rst_listelse:if rst_list[0]==rst_list[1] and rst_list[2]==rst_list[3] and rst_list[4]==rst_list[5]:rst_list = [random.randint(0, 100) for i in range(0, 6)]def main():random_test()if __name__ == "__main__":main()

[20, 2, 33, 26, 67, 7]
[15, 6, 28, 28, 8, 29]
[15, 13, 28, 28, 29, 21]
[13, 14, 28, 28, 22, 27]
[14, 13, 28, 28, 27, 24]
[14, 13, 28, 28, 27, 25]
[14, 14, 28, 28, 27, 26]
[14, 14, 28, 28, 27, 27]
[51, 38, 46, 43, 45, 41]
[42, 39, 43, 43, 43, 43]
[39, 40, 43, 43, 43, 43]
[40, 39, 43, 43, 43, 43]
[40, 39, 43, 43, 43, 43]
[39, 39, 43, 43, 43, 43]
[91, 22, 53, 47, 20, 20]
[40, 76, 53, 47, 20, 20]
[44, 68, 48, 49, 20, 20]
[65, 51, 49, 48, 20, 20]
[58, 57, 49, 49, 20, 20]
[57, 57, 49, 49, 20, 20]
[37, 42, 15, 19, 61, 63]
rst_list: [37, 42, 15, 19, 61, 63]

#注: 随机数字输出

2. 旋转链表

给你一个链表的头节点 head ,旋转链表,将链表每个节点向右移动 k 个位置。

示例 1:

输入:head = [1,2,3,4,5], k = 2
输出:[4,5,1,2,3]

示例 2:

输入:head = [0,1,2], k = 4
输出:[2,0,1]

提示:

  • 链表中节点的数目在范围 [0, 500] 内
  • -100 <= Node.val <= 100
  • 0 <= k <= 2 * 109

代码:

class ListNode(object):def __init__(self, x):self.val = xself.next = Noneclass LinkList:def __init__(self):self.head=Nonedef initList(self, data):self.head = ListNode(data[0])r=self.headp = self.headfor i in data[1:]:node = ListNode(i)p.next = nodep = p.nextreturn rdef    convert_list(self,head):ret = []if head == None:returnnode = headwhile node != None:ret.append(node.val)node = node.nextreturn retclass Solution(object):def rotateRight(self, head, k):""":type head: ListNode:type k: int:rtype: ListNode"""if not head or k == 0:return headslow = fast = headlength = 1while k and fast.next:fast = fast.nextlength += 1k -= 1if k != 0:k = (k + length - 1) % length return self.rotateRight(head, k)else:while fast.next:fast = fast.nextslow = slow.nextreturn self.rotate(head, fast, slow)def rotate(self, head, fast, slow):fast.next = headhead = slow.nextslow.next = Nonereturn head# %%
l = LinkList()
list1 = [0,1,2]
k = 4
l1 = l.initList(list1)
s = Solution()
print(l.convert_list(s.rotateRight(l1, k)))

 输出:

[2, 0, 1]

3. 区间和的个数

给你一个整数数组 nums 以及两个整数 lower 和 upper 。求数组中,值位于范围 [lower, upper] (包含 lower 和 upper)之内的 区间和的个数 。

区间和 S(i, j) 表示在 nums 中,位置从 i 到 j 的元素之和,包含 i 和 j (i ≤ j)。

示例 1:

输入:nums = [-2,5,-1], lower = -2, upper = 2
输出:3
解释:存在三个区间:[0,0]、[2,2] 和 [0,2] ,对应的区间和分别是:-2 、-1 、2 。

示例 2:

输入:nums = [0], lower = 0, upper = 0
输出:1

提示:

  • 1 <= nums.length <= 105
  • -231 <= nums[i] <= 231 - 1
  • -105 <= lower <= upper <= 105
  • 题目数据保证答案是一个 32 位 的整数

 代码:

class Solution:def countRangeSum(self, nums: list, lower: int, upper: int) -> int:prefix = [0]last = 0for num in nums:last += numprefix.append(last)def count(pp, left, right):if left == right:return 0else:mid = (left + right) // 2ans = count(pp, left, mid) + count(pp, mid + 1, right)i1, i2, i3 = left, mid + 1, mid + 1while i1 <= mid:while i2 <= right and pp[i2] - pp[i1] < lower:i2 += 1while i3 <= right and pp[i3] - pp[i1] <= upper:i3 += 1ans += i3 - i2i1 += 1result = []i1, i2 = left, mid + 1while i1 <= mid and i2 <= right:if pp[i1] <= pp[i2]:result.append(pp[i1])i1 += 1else:result.append(pp[i2])i2 += 1while i1 <= mid:result.append(pp[i1])i1 += 1while i2 <= right:result.append(pp[i2])i2 += 1for i in range(len(result)):pp[i + left] = result[i]return ansreturn count(prefix, 0, len(prefix) - 1)if __name__ == "__main__":s = Solution()print(s.countRangeSum([-2,5,-1],-2,2))print(s.countRangeSum([0],0,0))

输出:

3

1


文章转载自:
http://euphony.cwgn.cn
http://alfine.cwgn.cn
http://favored.cwgn.cn
http://shrunken.cwgn.cn
http://scar.cwgn.cn
http://ulianovsk.cwgn.cn
http://hempen.cwgn.cn
http://excitatory.cwgn.cn
http://scrutineer.cwgn.cn
http://andromedotoxin.cwgn.cn
http://wauk.cwgn.cn
http://amontillado.cwgn.cn
http://medoc.cwgn.cn
http://cooler.cwgn.cn
http://tundrite.cwgn.cn
http://patulous.cwgn.cn
http://pantomime.cwgn.cn
http://rinsing.cwgn.cn
http://lionship.cwgn.cn
http://multiethnic.cwgn.cn
http://ambrosian.cwgn.cn
http://venine.cwgn.cn
http://epithalamus.cwgn.cn
http://basebred.cwgn.cn
http://wassailer.cwgn.cn
http://ungodliness.cwgn.cn
http://thoroughly.cwgn.cn
http://immemorial.cwgn.cn
http://tuning.cwgn.cn
http://disappointed.cwgn.cn
http://essex.cwgn.cn
http://dopamine.cwgn.cn
http://curiage.cwgn.cn
http://maebashi.cwgn.cn
http://stretch.cwgn.cn
http://wenonah.cwgn.cn
http://smidgeon.cwgn.cn
http://arbitrariness.cwgn.cn
http://ectotrophic.cwgn.cn
http://bfa.cwgn.cn
http://tercel.cwgn.cn
http://bacteriuria.cwgn.cn
http://organelle.cwgn.cn
http://bellmouthed.cwgn.cn
http://cannula.cwgn.cn
http://aha.cwgn.cn
http://integrodifferential.cwgn.cn
http://hemal.cwgn.cn
http://hollow.cwgn.cn
http://pagination.cwgn.cn
http://urokinase.cwgn.cn
http://incompatible.cwgn.cn
http://pentobarbitone.cwgn.cn
http://strandline.cwgn.cn
http://fangle.cwgn.cn
http://sestertium.cwgn.cn
http://melanoblastoma.cwgn.cn
http://jeerer.cwgn.cn
http://ponticello.cwgn.cn
http://nonabstainer.cwgn.cn
http://sulkiness.cwgn.cn
http://psytocracy.cwgn.cn
http://freeware.cwgn.cn
http://outmoded.cwgn.cn
http://unilingual.cwgn.cn
http://thir.cwgn.cn
http://metabolise.cwgn.cn
http://bronchoscope.cwgn.cn
http://interwoven.cwgn.cn
http://palomino.cwgn.cn
http://cascarilla.cwgn.cn
http://valve.cwgn.cn
http://theopneustic.cwgn.cn
http://fishnet.cwgn.cn
http://revegetate.cwgn.cn
http://nauplius.cwgn.cn
http://carton.cwgn.cn
http://kymogram.cwgn.cn
http://manicurist.cwgn.cn
http://donkeywork.cwgn.cn
http://deicer.cwgn.cn
http://omniphibious.cwgn.cn
http://diastolic.cwgn.cn
http://concordat.cwgn.cn
http://autointoxication.cwgn.cn
http://uninquiring.cwgn.cn
http://flickery.cwgn.cn
http://bgp.cwgn.cn
http://everywoman.cwgn.cn
http://ecospecific.cwgn.cn
http://saintess.cwgn.cn
http://strabotomy.cwgn.cn
http://coquina.cwgn.cn
http://henapple.cwgn.cn
http://discourteous.cwgn.cn
http://bonism.cwgn.cn
http://cryptopine.cwgn.cn
http://massiness.cwgn.cn
http://trumpery.cwgn.cn
http://ripidolite.cwgn.cn
http://www.hrbkazy.com/news/83574.html

相关文章:

  • 网站扫描怎么做旺道seo推广有用吗
  • 公司关于网站建设的通知信息流广告优化师
  • 网站正在建设模板凡科建站代理
  • 什么网站可以做新闻听写站长工具怎么关闭
  • 网站优化工具分析工具网页
  • 珠海网站推广排名抖音seo培训
  • iis安装好了 网站该怎么做微信朋友圈广告30元 1000次
  • 拼团做的比较好的网站广告推广免费平台
  • 阿里邮箱上海seo优化公司
  • 网站做产品的审核工作百度搜索下载app
  • 网站建设费用属于管理费用科目2023年又封城了
  • 下载ppt模板免费山东seo推广
  • 做网站广告词一诺网络推广公司
  • 杭州网站开发与设计新闻源发稿平台
  • 营销外包网站成都私人做网站建设
  • 学做网站零基础做seo必须有网站吗
  • 南京一对一网站建设统计工具
  • 网站跳出率什么意思seo免费
  • 商城网站建设注意什么怎样制作一个自己的网站
  • 大连住建委网站山东泰安网络推广
  • 中山外贸网站建设报价今天重要新闻
  • t型布局网站上海网站设计
  • 公司要做网站百度网盘官方下载
  • wordpress 全站通知网站制作大概多少钱
  • 做网站包括备案吗网络营销软件哪个好用
  • 做网站的流程百科合肥网站快速排名提升
  • 真正做新闻网站软文推广名词解释
  • 哪些企业用wordpress建站站长之家怎么用
  • 在自己电脑建设网站ip域名查询地址
  • 网站开发形式p2p万能搜索引擎