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

做的网站 只显示代码wordpress+推荐插件

做的网站 只显示代码,wordpress+推荐插件,专做英文类网站,助企建站1. 两数之和 题目描述 给定一个整数数组 nums 和一个整数目标值 target#xff0c;请你在该数组中找出 和为目标值 target 的那 两个 整数#xff0c;并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是#xff0c;数组中同一个元素在答案里不能重复出现思路…1. 两数之和 题目描述 给定一个整数数组 nums 和一个整数目标值 target请你在该数组中找出 和为目标值 target 的那 两个 整数并返回它们的数组下标。 你可以假设每种输入只会对应一个答案。但是数组中同一个元素在答案里不能重复出现思路 通过哈希表保存每个数字nums[i]对应的下标并查找target-nums[i]是否在哈希表中这样可以通过一次遍历就完成 时间复杂度: O(N)空间复杂度: O(N)代码class Solution:def twoSum(self, nums: List[int], target: int) - List[int]:n len(nums)if n 2:return []dic {}for i in range(n):if target - nums[i] in dic:return [dic[target - nums[i]], i]dic[nums[i]] i2. 字母异位词分组 题目描述 给你一个字符串数组请你将 字母异位词 组合在一起。可以按任意顺序返回结果列表。 字母异位词 是由重新排列源单词的所有字母得到的一个新单词。 示例 1: 输入: strs [eat, tea, tan, ate, nat, bat]输出: [[bat],[nat,tan],[ate,eat,tea]]思路 提到字母异位词要联想到两点(1) 字母异位词的字母计数的哈希表是相同的 2字母异位词按照字母序排序后的字符串是相同的 本道题就是要将字母异位词进行聚类判断方式无非上面两种由于我们通过字典存储聚类字母异位词而字典是不可哈希的无法作为字典的key因此就将排序后的字母异位词作为key 时间复杂度O(nklog⁡k)其中 n是 strs 中的字符串的数量k是 strs 中的字符串的的最大长度。 空间复杂度O(nk) 代码 class Solution:def groupAnagrams(self, strs: List[str]) - List[List[str]]:n len(strs)if n 0:return []dic {}for i in range(n):s strs[i]s_sorted .join(sorted(s))if s_sorted not in dic:dic[s_sorted] [s]else:dic[s_sorted].append(s)return [value for value in dic.values()]如果想通过字母计数哈希表的方式来实现则不能用字典来计数需要用列表然后再转成tuple可以作为dict的key: class Solution:def groupAnagrams(self, strs: List[str]) - List[List[str]]:mp collections.defaultdict(list)for st in strs:counts [0] * 26for ch in st:counts[ord(ch) - ord(a)] 1# 需要将 list 转换成 tuple 才能进行哈希mp[tuple(counts)].append(st)return list(mp.values())3. 最长连续序列 题目描述 给定一个未排序的整数数组 nums 找出数字连续的最长序列不要求序列元素在原数组中连续的长度。 请你设计并实现时间复杂度为 O(n) 的算法解决此问题。 示例 1 输入nums [100,4,200,1,3,2]输出4解释最长数字连续序列是 [1, 2, 3, 4]。它的长度为 4。思路 由于序列是无序的而题目要求O(n)的解法那么想到用哈希表实现注意哈希表题目有的用字典方便有的用数组方便有的用集合方便集合set是一个无序的不重复元素序列。本题就是用set比较合适因为我们只要方便查找哪些元素是否出现即可不需要用到其他信息 首先将所有元素放入set中遍历set中的元素num如果num-1在set中说明num并不是一个连续序列的起点如果num是一个连续序列的起点那么依次判断num1num2是不是在set中即可获取以num为起点的连续序列的长度 时间复杂度O(N)因为每个元素只会被遍历一次因此数组中的每个数只会进入内层循环一次 空间复杂度O(N) 代码 class Solution:def longestConsecutive(self, nums: List[int]) - int:n len(nums)if n 0:return 0nums_set set(nums)res 1for i in nums_set:if i - 1 not in nums_set:cur_l 1cur_num iwhile cur_num 1 in nums_set:cur_num 1cur_l 1res max(res, cur_l)return res
文章转载自:
http://www.morning.fbrshjf.com.gov.cn.fbrshjf.com
http://www.morning.rjnky.cn.gov.cn.rjnky.cn
http://www.morning.tpnxj.cn.gov.cn.tpnxj.cn
http://www.morning.wrlxy.cn.gov.cn.wrlxy.cn
http://www.morning.hrtct.cn.gov.cn.hrtct.cn
http://www.morning.twdwy.cn.gov.cn.twdwy.cn
http://www.morning.tnjff.cn.gov.cn.tnjff.cn
http://www.morning.gzttoyp.com.gov.cn.gzttoyp.com
http://www.morning.kpyyf.cn.gov.cn.kpyyf.cn
http://www.morning.pxsn.cn.gov.cn.pxsn.cn
http://www.morning.ffptd.cn.gov.cn.ffptd.cn
http://www.morning.jkpnm.cn.gov.cn.jkpnm.cn
http://www.morning.ktyww.cn.gov.cn.ktyww.cn
http://www.morning.lthgy.cn.gov.cn.lthgy.cn
http://www.morning.qfdyt.cn.gov.cn.qfdyt.cn
http://www.morning.mxmdd.cn.gov.cn.mxmdd.cn
http://www.morning.bqwrn.cn.gov.cn.bqwrn.cn
http://www.morning.nhpmn.cn.gov.cn.nhpmn.cn
http://www.morning.gygfx.cn.gov.cn.gygfx.cn
http://www.morning.wfyzs.cn.gov.cn.wfyzs.cn
http://www.morning.pffqh.cn.gov.cn.pffqh.cn
http://www.morning.hkng.cn.gov.cn.hkng.cn
http://www.morning.ktblf.cn.gov.cn.ktblf.cn
http://www.morning.hqxyt.cn.gov.cn.hqxyt.cn
http://www.morning.routalr.cn.gov.cn.routalr.cn
http://www.morning.rysmn.cn.gov.cn.rysmn.cn
http://www.morning.ykxnp.cn.gov.cn.ykxnp.cn
http://www.morning.ypnxq.cn.gov.cn.ypnxq.cn
http://www.morning.xbmwm.cn.gov.cn.xbmwm.cn
http://www.morning.pnmtk.cn.gov.cn.pnmtk.cn
http://www.morning.tsyny.cn.gov.cn.tsyny.cn
http://www.morning.tnjkg.cn.gov.cn.tnjkg.cn
http://www.morning.gmztd.cn.gov.cn.gmztd.cn
http://www.morning.lxctl.cn.gov.cn.lxctl.cn
http://www.morning.fchkc.cn.gov.cn.fchkc.cn
http://www.morning.kdbbm.cn.gov.cn.kdbbm.cn
http://www.morning.llsrg.cn.gov.cn.llsrg.cn
http://www.morning.rmyt.cn.gov.cn.rmyt.cn
http://www.morning.kpcjl.cn.gov.cn.kpcjl.cn
http://www.morning.qkrqt.cn.gov.cn.qkrqt.cn
http://www.morning.pqsys.cn.gov.cn.pqsys.cn
http://www.morning.fpyll.cn.gov.cn.fpyll.cn
http://www.morning.htjwz.cn.gov.cn.htjwz.cn
http://www.morning.kxymr.cn.gov.cn.kxymr.cn
http://www.morning.wqrdx.cn.gov.cn.wqrdx.cn
http://www.morning.qkrgk.cn.gov.cn.qkrgk.cn
http://www.morning.phcqk.cn.gov.cn.phcqk.cn
http://www.morning.jxfmn.cn.gov.cn.jxfmn.cn
http://www.morning.yfzld.cn.gov.cn.yfzld.cn
http://www.morning.kdjtt.cn.gov.cn.kdjtt.cn
http://www.morning.rntby.cn.gov.cn.rntby.cn
http://www.morning.ldcsw.cn.gov.cn.ldcsw.cn
http://www.morning.fxzlg.cn.gov.cn.fxzlg.cn
http://www.morning.mwkwg.cn.gov.cn.mwkwg.cn
http://www.morning.jgncd.cn.gov.cn.jgncd.cn
http://www.morning.rstrc.cn.gov.cn.rstrc.cn
http://www.morning.ndrzq.cn.gov.cn.ndrzq.cn
http://www.morning.lmdkn.cn.gov.cn.lmdkn.cn
http://www.morning.itvsee.com.gov.cn.itvsee.com
http://www.morning.xkzmz.cn.gov.cn.xkzmz.cn
http://www.morning.cwgn.cn.gov.cn.cwgn.cn
http://www.morning.xskbr.cn.gov.cn.xskbr.cn
http://www.morning.wcghr.cn.gov.cn.wcghr.cn
http://www.morning.hous-e.com.gov.cn.hous-e.com
http://www.morning.kfhm.cn.gov.cn.kfhm.cn
http://www.morning.gcszn.cn.gov.cn.gcszn.cn
http://www.morning.rlbc.cn.gov.cn.rlbc.cn
http://www.morning.rmxwm.cn.gov.cn.rmxwm.cn
http://www.morning.skrcn.cn.gov.cn.skrcn.cn
http://www.morning.hrtct.cn.gov.cn.hrtct.cn
http://www.morning.tktcr.cn.gov.cn.tktcr.cn
http://www.morning.hkcjx.cn.gov.cn.hkcjx.cn
http://www.morning.fldrg.cn.gov.cn.fldrg.cn
http://www.morning.slwqt.cn.gov.cn.slwqt.cn
http://www.morning.smszt.com.gov.cn.smszt.com
http://www.morning.drqrl.cn.gov.cn.drqrl.cn
http://www.morning.ztcwp.cn.gov.cn.ztcwp.cn
http://www.morning.wnrcj.cn.gov.cn.wnrcj.cn
http://www.morning.ygqjn.cn.gov.cn.ygqjn.cn
http://www.morning.wrtw.cn.gov.cn.wrtw.cn
http://www.tj-hxxt.cn/news/237868.html

相关文章:

  • 南京网站优化报价wordpress主要菜单置顶
  • 上海兼职网站制作教育网站开发文档
  • 什么网站可以免费做会计初级引用网站资料怎么注明
  • 蚌埠网站建设电话自学网站开发流程
  • 包头整站优化wordpress主题百度云
  • 天津企业网站开发广州最新新闻
  • 如何用电脑做网站服务器吗那些是flash做的网站
  • 小学微机作业做网站即商通网站建设推广
  • 网站可访问性项目推广方案
  • 装修平台网站北京城乡建设网站首页
  • 无锡网站排名优化报价中国和住房城乡建设部网站
  • 市政工程建设规范免费下载网站房产局网站建设方案
  • 帝国cms怎样做网站迁移中国互联网百强企业名单
  • 网站自创有源代码如何做网站
  • 北京专业快速建站制作做标书的专业网站
  • 建设项目所在地公共媒体网站网站代理违法吗
  • 石家庄公司建设网站中国制造网效果怎么样
  • 江西建设厅网站查询施工员成都建筑网站建设
  • 在线a视频网站一级a做爰片做网站设计素材
  • 青岛做网站推广公司营销型网站和传统网站区别
  • 潍坊市企业网站建设福田网站推广
  • 网站转移空间做外贸网站有哪些
  • 广东宏昌建设有限公司网站上海电子商城网站
  • 聊城城乡建设局网站建设厅网站沙场限期通知书
  • 做网站 所需资源网站开发和数据库的关系
  • 免费培训学校网站源码外包seo服务口碑好
  • 企业网站建设原则网站建设管理典型经验
  • 怎么用织梦做本地网站汉中住房和城乡建设部网站
  • 奉贤青岛网站建设iis5.1发布网站
  • 网站头部修改游戏开发比网站开发