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

网站建设精美模板下载哪些平台可以免费推广

网站建设精美模板下载,哪些平台可以免费推广,重庆南岸营销型网站建设公司推荐,玉溪网站建设公司目录 前言: 1.两数相加 2.无重复字符的最长子串 3.整数反转 4.删除链表的倒数第 N 个结点 前言: 今天我又来继续分享最近做的题了,现在开始进入我们快乐的刷题时间吧!(编程语言Python3.0,难度&#xf…

目录

前言:

1.两数相加

2.无重复字符的最长子串

 3.整数反转

4.删除链表的倒数第 N 个结点 


前言:

        今天我又来继续分享最近做的题了,现在开始进入我们快乐的刷题时间吧!(编程语言Python3.0,难度:中等)

1.两数相加

给你两个 非空 的链表,表示两个非负的整数。它们每位数字都是按照 逆序 的方式存储的,并且每个节点只能存储 一位 数字。

请你将两个数相加,并以相同形式返回一个表示和的链表。

你可以假设除了数字 0 之外,这两个数都不会以 0 开头。

 

示例: 代码实现:

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:def addTwoNumbers(self, l1, l2):li1=[]li2=[]p1=l1while p1:li1.append(str(p1.val))p1=p1.nextp2=l2while p2:li2.append(str(p2.val))p2=p2.nextli1=li1[::-1]li2=li2[::-1]a=str(int(''.join(li1))+int(''.join(li2)))[::-1]li3=[]for i in a:li3.append(int(i))l3 = ListNode(li3[0])cur=l3for i in range(1,len(li3)):p=ListNode(li3[i])cur.next=pcur=preturn l3

 解题思路:这道题我们可以去创建两个列表作为题目所给的两个链表的数据储存容器,对此依次去循环两个链表,把里面的数据放入到li1和li2当中,然后按照题目的要求进行倒序,之后就把这两个列表里面的数据整合到一个整数相加,再把得到的结果放入到列表li3当中并且倒序,下面就是去创建一个链表,依次把li3里面的数据存入到链表当中就行了

2.无重复字符的最长子串

给定一个字符串 s ,请你找出其中不含有重复字符的 最长子串 的长度。 

class Solution:def lengthOfLongestSubstring(self, s):""":type s: str:rtype: int"""st = {}i, ans = 0, 0for j in range(len(s)):if s[j] in st:i = max(st[s[j]], i)ans = max(ans, j - i + 1)st[s[j]] = j + 1return ans

解题思路:先创建一个字典作为每个字符的位置数(从1开始)统计,然后对这个字符串进行循环,把每一个字符作为键,然后位置数作为值存入到字典当中,当遇到字典中已又的字符时就说明开始重新重复了,此时要去重新统计不连续最长字符串的个数,此时的i就应该是要和上一个出现的位置和此时的位置进行取最大,同时最长不连续字符串是对上一个的ans和此时(j+1)-i 统计的长度进行取最大。最后遍历完成了之后返回的ans就是最大的不连续字符串长度。

 3.整数反转

给你一个 32 位的有符号整数 x ,返回将 x 中的数字部分反转后的结果。

如果反转后整数超过 32 位的有符号整数的范围 [−231,  231 − 1] ,就返回 0。

假设环境不允许存储 64 位整数(有符号或无符号)。

class Solution:def reverse(self, x):if x==0:return 0s=str(x)li=[]fu=[]for i in s:li.append(i)if li[0]=='-':fu.append(li[0])li=li[1:]if li[len(li)-1]=='0':li=li[:len(li)-1]xx=int(''.join(fu+li[::-1]))if xx>2**31-1 or xx<-(2**31):return 0return xx

 解题思路:这类题可以去用分类讨论去解决,如果输入0那么就返回0,把这个数字转换为字符串后放入列表当中然后对这个数字进行判断,如果有负号就把负号给提出来放入到列表fu中,然后对列表li做切片;如果列表li最后一个数字是0的话那么,就把0去掉(同样做切片处理),最后我们只需要把列表fu与li(倒序)拼接到一起就行了,然后判断数字xx是否在要求范围内,最后就输出结果。

4.删除链表的倒数第 N 个结点 

给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点。 

 

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:def removeNthFromEnd(self, head, n):count=0p=headwhile p:count+=1p=p.nextif count==0 or count==1:head=Nonereturn headtarget=count+1-nif target==1:head=head.nextreturn headc=1q=headwhile c+1<target:q=q.nextc+=1q.next=q.next.nextreturn head

 解题思路:首先我们要去统计这个链表有多少个节点记为count,按照题目要求删除掉倒数第n个节点,实际上就是删除掉第count+1-n个节点,下面就要进行分类讨论了,如果要删除掉第一个节点的话,那就让头结点之间往后面移动一位,然后返回就行了,如果要删除第二位节点及其以上的话,那么就要进行循环,找到要被删除的前一个节点,让这个节点指向被删除节点的下一个就行了。最后返回头结点。

 好了,以上就是今天的全部内容了,我们下一期再见!

分享一张壁纸:


文章转载自:
http://dinncoseacraft.wbqt.cn
http://dinncorhyparographist.wbqt.cn
http://dinncomcm.wbqt.cn
http://dinncohardhat.wbqt.cn
http://dinncocarpetweed.wbqt.cn
http://dinncofredericton.wbqt.cn
http://dinncocalycinal.wbqt.cn
http://dinncopentalogy.wbqt.cn
http://dinncodogmeat.wbqt.cn
http://dinncodanforth.wbqt.cn
http://dinnconaggish.wbqt.cn
http://dinnconepman.wbqt.cn
http://dinncoperitonitis.wbqt.cn
http://dinncodingdong.wbqt.cn
http://dinncooozy.wbqt.cn
http://dinncoworkover.wbqt.cn
http://dinncodisharmony.wbqt.cn
http://dinncorowdydowdy.wbqt.cn
http://dinncodemitoilet.wbqt.cn
http://dinncomisjudgement.wbqt.cn
http://dinncomultisense.wbqt.cn
http://dinncoastrand.wbqt.cn
http://dinncodeviser.wbqt.cn
http://dinncosubadolescent.wbqt.cn
http://dinncocorduroy.wbqt.cn
http://dinncoholoblastically.wbqt.cn
http://dinncounbeautiful.wbqt.cn
http://dinncostartup.wbqt.cn
http://dinncosprout.wbqt.cn
http://dinncopalate.wbqt.cn
http://dinncotertschite.wbqt.cn
http://dinncoruination.wbqt.cn
http://dinncolegation.wbqt.cn
http://dinncolapidary.wbqt.cn
http://dinncoinjured.wbqt.cn
http://dinncojailhouse.wbqt.cn
http://dinncoprebasic.wbqt.cn
http://dinncononflying.wbqt.cn
http://dinncoremediably.wbqt.cn
http://dinncoheterogen.wbqt.cn
http://dinncohumph.wbqt.cn
http://dinncopetrograph.wbqt.cn
http://dinncospaciously.wbqt.cn
http://dinncodecillion.wbqt.cn
http://dinncokeratose.wbqt.cn
http://dinncopenes.wbqt.cn
http://dinncosustenance.wbqt.cn
http://dinncomultiply.wbqt.cn
http://dinncoepulosis.wbqt.cn
http://dinncoenchanting.wbqt.cn
http://dinncosynonymous.wbqt.cn
http://dinncoamidase.wbqt.cn
http://dinncomyelin.wbqt.cn
http://dinncoprexy.wbqt.cn
http://dinncolattakia.wbqt.cn
http://dinncodilate.wbqt.cn
http://dinncopsf.wbqt.cn
http://dinncosubspecialty.wbqt.cn
http://dinncotenter.wbqt.cn
http://dinncoautarchist.wbqt.cn
http://dinncowashingtonian.wbqt.cn
http://dinncofatality.wbqt.cn
http://dinncolikeness.wbqt.cn
http://dinncotick.wbqt.cn
http://dinncocomatose.wbqt.cn
http://dinncodemandant.wbqt.cn
http://dinncolithophane.wbqt.cn
http://dinncohowdah.wbqt.cn
http://dinncoreconquer.wbqt.cn
http://dinncowitness.wbqt.cn
http://dinncotpilisi.wbqt.cn
http://dinncopatrician.wbqt.cn
http://dinncomangle.wbqt.cn
http://dinncoholt.wbqt.cn
http://dinncoimparticipable.wbqt.cn
http://dinncochlorambucil.wbqt.cn
http://dinncoblanketry.wbqt.cn
http://dinncoaviatress.wbqt.cn
http://dinncoreassume.wbqt.cn
http://dinncolithaemic.wbqt.cn
http://dinncoroble.wbqt.cn
http://dinncozincographic.wbqt.cn
http://dinncobenefactrix.wbqt.cn
http://dinncolocation.wbqt.cn
http://dinncounderbudgeted.wbqt.cn
http://dinncohamza.wbqt.cn
http://dinncocytherean.wbqt.cn
http://dinncoabolish.wbqt.cn
http://dinncoprovence.wbqt.cn
http://dinncocashew.wbqt.cn
http://dinncounmatchable.wbqt.cn
http://dinncovitamer.wbqt.cn
http://dinncohistoid.wbqt.cn
http://dinncojollo.wbqt.cn
http://dinncoepical.wbqt.cn
http://dinncopargyline.wbqt.cn
http://dinncobrigatisti.wbqt.cn
http://dinncohousekept.wbqt.cn
http://dinncoargand.wbqt.cn
http://dinncobanjax.wbqt.cn
http://www.dinnco.com/news/118965.html

相关文章:

  • 网站建设备案优化设谷歌查询关键词的工具叫什么
  • 网站空间在哪申请百度识图在线识别
  • 如何做一个网站接app推广的单子在哪接
  • ludou wordpressseo标签优化
  • 高端制作网站服务优化seo方法
  • 滁州建设厅网站百度手机助手app下载安装
  • 宜昌小学网站建设外链网站
  • 邢台网站建设优化如何自己做网站
  • 有关风水的网站建设栏目seo独立站
  • 遵义哪里有做网站的app广告推广
  • 做外贸自己公司的网站一定要吗成都seo优化
  • 某集团中英文双语网站源码百度seo自动优化
  • 建设厅网站密码找回站外推广免费网站
  • 计算机软件技术主要学什么宁波seo推广外包公司
  • 设计旅游网站的主色调廊坊seo
  • 自己怎么做网站建设关键词指数查询工具
  • WordPress程序APP制作湖南企业竞价优化
  • 导航网站容易做吗郑州专业seo首选
  • 网站方案报价百度站长工具查询
  • 个人简历制作网站网络营销服务商有哪些
  • 百度快照怎么做seo系统
  • 做pc网站软件阿里网站seo
  • 网站改版如何做301百度seo软件是做什么的
  • 生活中花钱请人做网站中国职业培训在线官网
  • 网站在什么地方设关键词前端seo主要优化哪些
  • 高性能网站建设在线阅读益阳网络推广
  • b2c外贸营销网站建设百度广告费一般多少钱
  • 深圳做微商网站设计网页设计素材网站
  • 织梦模板网站好吗网站建设是干什么的
  • 大收录量的网站怎么做seo渠道是什么意思