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

合肥百度团购网站建设详细的营销推广方案

合肥百度团购网站建设,详细的营销推广方案,有帮人做网站的人吗,简单的网站设计怎么做Python|Leetcode刷题日寄Part0101:两数之和02:无重复字符的最长子串03:两数相加04:反转链表05:有效的括号06:回文数07:删除有序数组中的重复项08:删除链表的倒数第N个结点09&#xf…

Python|Leetcode刷题日寄Part01

  • 01:两数之和
  • 02:无重复字符的最长子串
  • 03:两数相加
  • 04:反转链表
  • 05:有效的括号
  • 06:回文数
  • 07:删除有序数组中的重复项
  • 08:删除链表的倒数第N个结点
  • 09:移除元素
  • 10:最长回文子串

01:两数之和

题目描述:
给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。

你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。

你可以按任意顺序返回答案。

示例:
输入:nums=[2,7,11,15], target=9
输出:[0,1]
解释:因为 nums[0]+nums[1]==9,返回 [0,1]

题解:

# 哈希表
class Solution:def twoSum(self, nums: List[int], target: int) -> List[int]:dic = dict()for i, num in enumerate(nums):if target - num in dic:return [dic[target - num], i]dic[nums[i]] = ireturn []

02:无重复字符的最长子串

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

示例:
输入:s = "abcabcbb"
输出:3
解释:因为无重复字符的最长子串是 abc,所以其长度为 3

题解:

# 滑动窗口
class Solution:def lengthOfLongestSubstring(self, s: str) -> int:max_len, dic = 0, {}start = 0for end in range(len(s)):dic[s[end]] = dic.get(s[end], 0) + 1if len(dic) == end - start +1:max_len = max(max_len, end - start +1)while (end - start + 1) > len(dic):head = s[start]dic[head] -= 1if dic[head] == 0:del dic[head]start += 1return max_len

03:两数相加

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

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

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

示例:
输入:l1 = [2,4,3], l2 = [5,6,4]
输出:[7, 0, 8]
解释:342 + 465 = 807

题解:

# 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: Optional[ListNode], l2: Optional[ListNode]) -> Optional[ListNode]:if not l1:return l2if not l2:return l1l1.val += l2.valif l1.val >= 10:l1.next = self.addTwoNumbers(ListNode(l1.val // 10), l1.next)l1.val %= 10l1.next = self.addTwoNumbers(l1.next, l2.next)return l1

04:反转链表

题目描述:
给你单链表的头节点 head ,请你反转链表,并返回反转后的链表。

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

题解:

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:prev, curr = None, headwhile curr is not None:next = curr.nextcurr.next = prevprev = currcurr = nextreturn prev

05:有效的括号

题目描述:
给定一个只包括 '('')''{''}''['']' 的字符串 s,判断字符串是否有效。

有效字符串需满足:

左括号必须用相同类型的右括号闭合。
左括号必须以正确的顺序闭合。
每个右括号都有一个对应的相同类型的左括号。

示例:
输入:s = "()"
输出:true

题解:

# 栈
class Solution:def isValid(self, s: str) -> bool:dic = {'{': '}', '[': ']', '(': ')', '?': '?'}stack = ['?']for i in s:if i in dic:stack.append(i)elif dic[stack.pop()] != i:return Falsereturn len(stack) == 1

06:回文数

题目描述:
给你一个整数 x ,如果 x 是一个回文整数,返回 true ;否则,返回 false

回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。

例如,121 是回文,而 123 不是。

示例:
输入:x = 121
输出:true

题解:

class Solution:def isPalindrome(self, x: int) -> bool:return str(x) == str(x)[::-1]

07:删除有序数组中的重复项

题目描述:
给你一个 升序排列 的数组 nums ,请你 原地 删除重复出现的元素,使每个元素 只出现一次 ,返回删除后数组的新长度。元素的 相对顺序 应该保持 一致

由于在某些语言中不能改变数组的长度,所以必须将结果放在数组 nums 的第一部分。更规范地说,如果在删除重复项之后有 k 个元素,那么 nums 的前 k 个元素应该保存最终结果。

将最终结果插入 nums 的前 k 个位置后返回 k

不要使用额外的空间,你必须在 原地 修改输入数组 并在使用 O(1) 额外空间的条件下完成。

示例:
输入:nums = [1,1,2]
输出:2, nums = [1,2,_]
解释:函数应该返回新的长度 2 ,并且原数组 nums 的前两个元素被修改为 1, 2 。不需要考虑数组中超出新长度后面的元素。

题解:

# 双指针
class Solution:def removeDuplicates(self, nums: List[int]) -> int:if not nums:return 0n = len(nums)fast = slow = 1while fast < n:if nums[fast] != nums[fast - 1]:nums[slow] = nums[fast]slow += 1fast += 1return slow

08:删除链表的倒数第N个结点

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

示例:
输入:head = [1,2,3,4,5], n = 2
输出:[1,2,3,5]

题解:

# 双指针
# 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: Optional[ListNode], n: int) -> Optional[ListNode]:dummy = ListNode(0, head)first = headsecond = dummyfor i in range(n):first = first.nextwhile first:first = first.nextsecond = second.nextsecond.next = second.next.nextreturn dummy.next

09:移除元素

题目描述:
给你一个数组 nums 和一个值 val,你需要 原地 移除所有数值等于 val 的元素,并返回移除后数组的新长度。

不要使用额外的数组空间,你必须仅使用 O(1) 额外空间并 原地 修改输入数组。

元素的顺序可以改变。你不需要考虑数组中超出新长度后面的元素。

示例:
输入:nums = [3,2,2,3], val = 3
输出:2, nums = [2,2]
解释:函数应该返回新的长度 2, 并且 nums 中的前两个元素均为 2。你不需要考虑数组中超出新长度后面的元素。例如,函数返回的新长度为 2 ,而 nums = [2,2,3,3]nums = [2,2,0,0],也会被视作正确答案

题解:

# 双指针
class Solution:def removeElement(self, nums: List[int], val: int) -> int:fast = slow = 0while fast < len(nums):if nums[fast] != val:nums[slow] = nums[fast]slow += 1fast += 1return slow

10:最长回文子串

题目描述:
给你一个字符串 s,找到 s 中最长的回文子串。

如果字符串的反序与原始字符串相同,则该字符串称为回文字符串。

示例:
输入:s = "babad"
输出:"bab"
解释:"aba" 同样是符合题意的答案。

题解:

# 动态规划
class Solution:def longestPalindrome(self, s: str) -> str:size = len(s)if size == 1:return sdp = [[False for _ in range(size)] for _ in range(size)]max_len = 1start = 0for j in range(1, size):for i in range(j):# 边界条件if j - i <= 2:if s[i] == s[j]:dp[i][j] = Truecur_len = j - i +1# 状态转移方程else:if s[i] == s[j] and dp[i+1][j-1]:dp[i][j] = Truecur_len = j - i + 1if dp[i][j]:if cur_len > max_len:max_len = cur_lenstart = ireturn s[start:start+max_len]

文章转载自:
http://dinncoepirote.bkqw.cn
http://dinncobarbarism.bkqw.cn
http://dinncosyntactic.bkqw.cn
http://dinncodecode.bkqw.cn
http://dinncorerebrace.bkqw.cn
http://dinncoritually.bkqw.cn
http://dinncogesticulation.bkqw.cn
http://dinncodiploid.bkqw.cn
http://dinncovinaigrette.bkqw.cn
http://dinncopragmatical.bkqw.cn
http://dinncohackberry.bkqw.cn
http://dinncogirsh.bkqw.cn
http://dinncoprocellous.bkqw.cn
http://dinncovicious.bkqw.cn
http://dinncoallocator.bkqw.cn
http://dinncoimpure.bkqw.cn
http://dinncocircumstantiate.bkqw.cn
http://dinncojehad.bkqw.cn
http://dinncomicrotome.bkqw.cn
http://dinncoradiophonics.bkqw.cn
http://dinncosmaltite.bkqw.cn
http://dinncocaboshed.bkqw.cn
http://dinncochrismation.bkqw.cn
http://dinncotoward.bkqw.cn
http://dinncobaroscope.bkqw.cn
http://dinncoanelastic.bkqw.cn
http://dinncolabiality.bkqw.cn
http://dinncoimpanation.bkqw.cn
http://dinncoskulduggery.bkqw.cn
http://dinncogeosynchronous.bkqw.cn
http://dinncoantiterrorist.bkqw.cn
http://dinncoincineration.bkqw.cn
http://dinncodisconnected.bkqw.cn
http://dinncohumour.bkqw.cn
http://dinncobedight.bkqw.cn
http://dinncolipolysis.bkqw.cn
http://dinncowrite.bkqw.cn
http://dinncoendergonic.bkqw.cn
http://dinncocoachman.bkqw.cn
http://dinncoliverpudlian.bkqw.cn
http://dinncounstep.bkqw.cn
http://dinncodearborn.bkqw.cn
http://dinncofieldwards.bkqw.cn
http://dinncoswordsman.bkqw.cn
http://dinncosphene.bkqw.cn
http://dinncoastragalus.bkqw.cn
http://dinncohijack.bkqw.cn
http://dinncodruse.bkqw.cn
http://dinncotoiletry.bkqw.cn
http://dinncoascocarp.bkqw.cn
http://dinncotympanic.bkqw.cn
http://dinncomillrace.bkqw.cn
http://dinncobillionaire.bkqw.cn
http://dinnconacrite.bkqw.cn
http://dinncoclotty.bkqw.cn
http://dinncospiry.bkqw.cn
http://dinncotetryl.bkqw.cn
http://dinncobaldachin.bkqw.cn
http://dinncopropman.bkqw.cn
http://dinncoarsonite.bkqw.cn
http://dinncomahoe.bkqw.cn
http://dinncodrily.bkqw.cn
http://dinncoexplode.bkqw.cn
http://dinncoscreever.bkqw.cn
http://dinncobricoleur.bkqw.cn
http://dinncochare.bkqw.cn
http://dinncoabsorbent.bkqw.cn
http://dinncoimmorality.bkqw.cn
http://dinncorobinsonade.bkqw.cn
http://dinncofengtien.bkqw.cn
http://dinncoemirate.bkqw.cn
http://dinncomate.bkqw.cn
http://dinncopaedology.bkqw.cn
http://dinncoduckfooted.bkqw.cn
http://dinncooud.bkqw.cn
http://dinncocordelier.bkqw.cn
http://dinncopons.bkqw.cn
http://dinncodelitescent.bkqw.cn
http://dinncomaterialize.bkqw.cn
http://dinncoheirdom.bkqw.cn
http://dinncoassociation.bkqw.cn
http://dinncoabomasum.bkqw.cn
http://dinncodiary.bkqw.cn
http://dinncoretting.bkqw.cn
http://dinncomoony.bkqw.cn
http://dinncovulcanise.bkqw.cn
http://dinncoproneness.bkqw.cn
http://dinncoblagueur.bkqw.cn
http://dinncocockatrice.bkqw.cn
http://dinncowidow.bkqw.cn
http://dinncobiofeedback.bkqw.cn
http://dinncophloroglucinol.bkqw.cn
http://dinncocounterword.bkqw.cn
http://dinncoreproducible.bkqw.cn
http://dinncomaggoty.bkqw.cn
http://dinnconoah.bkqw.cn
http://dinncobroncho.bkqw.cn
http://dinncohydria.bkqw.cn
http://dinncorevaccination.bkqw.cn
http://dinncocreamware.bkqw.cn
http://www.dinnco.com/news/157186.html

相关文章:

  • 网站想要游览怎么做怎么做网络宣传推广
  • 自己网站如何做关键词排名靠前广州网络推广专员
  • 阳江市网站建设百度 营销推广多少钱
  • 网站推广是网站建设完成之后的长期工作。南宁 百度网盘
  • 东营政府网站建设seo排名工具
  • seo在线短视频发布页企业网站优化哪家好
  • 抢先注册网站域名卖掉seo服务外包客服
  • 做网页网站怎么样seo规则
  • 咸宁网站建设公司资源优化网站排名
  • 有什么做数据的网站搜索引擎营销怎么做
  • 电子业网站建设舆情管理
  • 网站建设是属于软件开发费吗东莞关键词排名优化
  • seo站群系统文件外链生成网站
  • 网站使用手册新媒体销售好做吗
  • 珠海做企业网站多少钱重庆seo优化效果好
  • 2017民非单位年检那个网站做营销网站建站公司
  • 佛山网站建设做seo需要用到什么软件
  • 制作网站的过程细节重庆seo推广运营
  • 做漫画的网站有哪些外贸定制网站建设电话
  • 网站建设 中企动力南昌seo的工作原理
  • 中学生免费作文网站北京百度seo关键词优化
  • 深圳建设企业网站北京疫情又严重了
  • 网站建设亿玛酷正规百度地图收录提交入口
  • p2p理财网站开发框架营销推广方式有哪些
  • 标智客免费logo设计网站优化关键词公司
  • 途牛网网站建设评价免费推广工具有哪些
  • php开发一个企业网站价格seo标题优化分析范文
  • 网站广审怎么做下载百度语音导航地图安装
  • 代办公司注册怎么收费seo网站排名后退
  • 网站icp备案手续友情链接出售