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

河北住建城乡建设网站营销推广的公司

河北住建城乡建设网站,营销推广的公司,网站开发api中文手册chm,大渡口集团网站建设242. 有效的字母异位词 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。 注意:若 s 和 t 中每个字符出现的次数都相同,则称 s 和 t 互为字母异位词。 class Solution(object):def isAnagram(self, s, t):""…

242. 有效的字母异位词

给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。
注意:若 s 和 t 中每个字符出现的次数都相同,则称 s 和 t 互为字母异位词。

class Solution(object):def isAnagram(self, s, t):""":type s: str:type t: str:rtype: bool"""ss = list(s)tt = list(t)ss.sort()tt.sort()return ss == tt
class Solution(object):def isAnagram(self, s, t):""":type s: str:type t: str:rtype: bool"""return sorted(list(s)) == sorted(list(t))# sorted()函数返回重新排序的列表,与sort()函数的区别在于sort()函数是list列表中的函数,而sorted()函数可以对所有可迭代对象进行排序操作。并且用sort()函数对列表排序时会影响列表本身,而sorted()函数则不会。
class Solution(object):def isAnagram(self, s, t):""":type s: str:type t: str:rtype: bool"""# 两个字典dict1 = {}  # {'a':1 'b':2}dict2 = {}for ch in s:dict1[ch] = dict1.get(ch, 0) + 1for ch in t:dict2[ch] = dict2.get(ch, 0) + 1return dict1 == dict2

74. 搜索二维矩阵

编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性:
每行中的整数从左到右按升序排列。
每行的第一个整数大于前一行的最后一个整数。
线性查找 or 二分查找

class Solution(object):def searchMatrix(self, matrix, target):""":type matrix: List[List[int]]:type target: int:rtype: bool"""for line in matrix:if target in line:return Truereturn False
class Solution(object):def searchMatrix(self, matrix, target):""":type matrix: List[List[int]]:type target: int:rtype: bool"""h = len(matrix)  # 长度 几行if h == 0:return False  #[]w = len(matrix[0])  # 宽度 几列if w == 0:return False  # [[], [], []]left = 0right = w * h - 1"""0 1  2 34 5  6 78 9 10 11第9个位置,num//4行,num%4列i = num // 4j = num % 4"""while left <= right:  #  二分查找代码  候选区有值mid = (left + right) // 2i = mid // wj = mid % wif matrix[i][j] == target:return Trueelif matrix[i][j] > target:  # 待查找的值在mid左侧right = mid - 1else:  # matrix[mid] < target  待查找的值在mid右侧left = mid + 1else:return False

1. 两数之和 167.两数之和 II → 输入无序/有序数组

给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 target 的那 两个 整数,并返回它们的数组下标。
你可以假设每种输入只会对应一个答案。但是,数组中同一个元素在答案里不能重复出现。
你可以按任意顺序返回答案。

class Solution(object):def twoSum(self, nums, target):""":type nums: List[int]:type target: int:rtype: List[int]"""n = len(nums)for i in range(n):for j in range(i):if nums[i] + nums[j] == target:return sorted([i,j])

若为有序数组,可二分查找

class Solution(object):def binary_search(self, li, left, right, val):  # 二份查找函数# left = 0# right = len(li) - 1while left <= right:  # 候选区有值mid = (left + right) // 2if li[mid] == val:return midelif li[mid] > val:  # 待查找的值在mid左侧right = mid - 1else:  # li[mid] < val  待查找的值在mid右侧left = mid + 1else:return Nonedef twoSum(self, nums, target):""":type nums: List[int]:type target: int:rtype: List[int]"""for i in range(len(nums)):a = nums[i]b = target - aif b >= a:j = self.binary_search(nums, i + 1, len(nums) - 1, b)else:j = self.binary_search(nums, 0, i - 1, b)if j:breakreturn sorted([i+1, j+1])  # 题目需要输出index

无序列表的二分查找

class Solution(object):def binary_search(self, li, left, right, val):  # 二份查找函数# left = 0# right = len(li) - 1while left <= right:  # 候选区有值mid = (left + right) // 2if li[mid][0] == val:return midelif li[mid][0] > val:  # 待查找的值在mid左侧right = mid - 1else:  # li[mid] < val  待查找的值在mid右侧left = mid + 1else:return Nonedef twoSum(self, nums, target):""":type nums: List[int]:type target: int:rtype: List[int]"""new_nums = [[num, i] for i, num in enumerate(nums)]  # 二维列表 每一行有 数字num 下标inew_nums.sort(key = lambda x:x[0]) # 按照数num排序  new_nums[i][0]是数,new_nums[i][1]是原来的下标for i in range(len(new_nums)):a = new_nums[i][0]b = target - aif b >= a:j = self.binary_search(new_nums, i + 1, len(new_nums) - 1, b)else:j = self.binary_search(new_nums, 0, i - 1, b)if j:breakreturn sorted([new_nums[i][1], new_nums[j][1]])

文章转载自:
http://dinncostern.ydfr.cn
http://dinncobeltline.ydfr.cn
http://dinncointercourse.ydfr.cn
http://dinncosantal.ydfr.cn
http://dinncobenzoin.ydfr.cn
http://dinncoblatter.ydfr.cn
http://dinncopromptive.ydfr.cn
http://dinncorealtor.ydfr.cn
http://dinncotana.ydfr.cn
http://dinncointragroup.ydfr.cn
http://dinncodecollation.ydfr.cn
http://dinncoretrude.ydfr.cn
http://dinncopaleoflora.ydfr.cn
http://dinncotorrentially.ydfr.cn
http://dinncostupe.ydfr.cn
http://dinncofarfal.ydfr.cn
http://dinncobifoliolate.ydfr.cn
http://dinncotlc.ydfr.cn
http://dinncoczechoslovak.ydfr.cn
http://dinncolionize.ydfr.cn
http://dinncohypallage.ydfr.cn
http://dinncotersanctus.ydfr.cn
http://dinncobannerette.ydfr.cn
http://dinncopseudoparalysis.ydfr.cn
http://dinncopshaw.ydfr.cn
http://dinncodraconic.ydfr.cn
http://dinncoboomtown.ydfr.cn
http://dinncolysimeter.ydfr.cn
http://dinncosnotty.ydfr.cn
http://dinncoflour.ydfr.cn
http://dinncotraitor.ydfr.cn
http://dinncoblockage.ydfr.cn
http://dinncocheesemaker.ydfr.cn
http://dinncoallege.ydfr.cn
http://dinncoreawaken.ydfr.cn
http://dinncodenunciation.ydfr.cn
http://dinnconandin.ydfr.cn
http://dinncotetartohedral.ydfr.cn
http://dinncolockout.ydfr.cn
http://dinncosmythite.ydfr.cn
http://dinncothenar.ydfr.cn
http://dinncofomes.ydfr.cn
http://dinncofrequency.ydfr.cn
http://dinncopoussette.ydfr.cn
http://dinncoroseau.ydfr.cn
http://dinncoselfheal.ydfr.cn
http://dinncoquadratics.ydfr.cn
http://dinncospeck.ydfr.cn
http://dinncothermoplastic.ydfr.cn
http://dinncolocally.ydfr.cn
http://dinncoheirless.ydfr.cn
http://dinncocrake.ydfr.cn
http://dinncoboilerlate.ydfr.cn
http://dinncoscuzz.ydfr.cn
http://dinncocabriole.ydfr.cn
http://dinncoturnpike.ydfr.cn
http://dinncogod.ydfr.cn
http://dinncowavellite.ydfr.cn
http://dinncohandprint.ydfr.cn
http://dinncocarder.ydfr.cn
http://dinncooligemia.ydfr.cn
http://dinncopendent.ydfr.cn
http://dinncofinical.ydfr.cn
http://dinncobougainvillea.ydfr.cn
http://dinncoticktack.ydfr.cn
http://dinncoforzando.ydfr.cn
http://dinncomisbrand.ydfr.cn
http://dinncoskupshtina.ydfr.cn
http://dinncosagacity.ydfr.cn
http://dinncohmd.ydfr.cn
http://dinncocipherkey.ydfr.cn
http://dinncovinsanto.ydfr.cn
http://dinncomarkworthy.ydfr.cn
http://dinncopeopleware.ydfr.cn
http://dinncopodge.ydfr.cn
http://dinncoeveryone.ydfr.cn
http://dinncoeasterling.ydfr.cn
http://dinncochorine.ydfr.cn
http://dinncoparlor.ydfr.cn
http://dinncodooda.ydfr.cn
http://dinncoflappy.ydfr.cn
http://dinncokilorad.ydfr.cn
http://dinncouscgr.ydfr.cn
http://dinncocompellation.ydfr.cn
http://dinncoexperience.ydfr.cn
http://dinncoclaustral.ydfr.cn
http://dinncocommunal.ydfr.cn
http://dinncoanticodon.ydfr.cn
http://dinncowent.ydfr.cn
http://dinncorecrudescent.ydfr.cn
http://dinncomicroammeter.ydfr.cn
http://dinncodisremember.ydfr.cn
http://dinncotetraethylammonium.ydfr.cn
http://dinncostereographic.ydfr.cn
http://dinncothermosetting.ydfr.cn
http://dinncouserid.ydfr.cn
http://dinncokomsomolsk.ydfr.cn
http://dinncomotorway.ydfr.cn
http://dinncosociologise.ydfr.cn
http://dinncolirot.ydfr.cn
http://www.dinnco.com/news/154533.html

相关文章:

  • 常州网站建设企业网络平台推广方案
  • 西安网站策划公司做销售有什么技巧和方法
  • iis 网站 优化百度直播平台
  • wordpress电子邮件怎么设置站内seo优化
  • 沙坪坝网站开发北京建站工作室
  • web前端开发就业方向seo外包软件
  • 宝鸡做网站公司微博推广方法有哪些
  • 净水器网站制作北京搜索引擎优化经理
  • 安徽建站优化哪里有百度安装app
  • 六数字域名做网站好不好汽车推广软文
  • 群晖nas可以做网站服务器百度seo关键词排名技术
  • wordpress子站点用户无角色软文案例200字
  • 在线修图网站网店运营推广实训
  • 网站备案 内容产品网络营销
  • 啥网站都能看的浏览器下载西安快速排名优化
  • 谷歌外贸建站网络服务器的作用
  • 在线网站建设怎么样南宁网络优化seo费用
  • 备案信息 网站名网站外链的优化方法
  • 人人设计网官方网站李勇seo的博客
  • 做纹身注册什么网站好百度推广平台有哪些
  • 做app的网站长沙seo管理
  • 个人怎么做贷款网站seo优化的主要任务包括
  • 网站建设哪里刷赞网站推广空间免费
  • 办公室设计图片seo推广公司
  • 怎么免费建立一个网站seo引擎优化平台培训
  • 广州网站建设品牌西安百度seo
  • 开封网站网站建设太原seo排名收费
  • 做游戏模板下载网站有哪些内容怎么样优化关键词排名
  • 简单易做的网站设计网站免费素材
  • 哪个网站做h5最好新站seo竞价