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

网站建设及维护服务技术指标抖音推广运营公司

网站建设及维护服务技术指标,抖音推广运营公司,专业的深圳网站建设,在哪找做网站的文章目录Google的一道经典面试题 - 767. 重构字符串767. 重构字符串1054. 距离相等的条形码结论Google的一道经典面试题 - 767. 重构字符串 767. 重构字符串 题目链接:767. 重构字符串 题目大意:给定一个字符串 s ,检查是否能重新排布其中的…

文章目录

  • Google的一道经典面试题 - 767. 重构字符串
    • 767. 重构字符串
    • 1054. 距离相等的条形码
  • 结论

Google的一道经典面试题 - 767. 重构字符串

767. 重构字符串

题目链接:767. 重构字符串
题目大意:给定一个字符串 s ,检查是否能重新排布其中的字母,使得两相邻的字符不同。
返回 s 的任意可能的重新排列。若不可行,返回空字符串 “” 。

注意:(1)1 <= s.length <= 500;(2)s 只包含小写字母。

示例:

输入: s = "aab"
输出: "aba"输入: s = "aaab"
输出: ""

参考代码:

class Solution:def reorganizeString(self, s: str) -> str:cnt = Counter(s)st = sorted(cnt,key=lambda k:0-cnt[k])if cnt[st[0]] > (len(s)+1)//2: return ""res = []for i in st:res += [i]*cnt[i]ans = [None for _ in range(len(res))]ans[::2] = res[:len(ans[::2])]ans[1::2] = res[len(ans[::2]):]return ''.join(ans)
  • 时间复杂度:O(n+∣Σ∣)O(n+|\Sigma|)O(n+∣Σ∣),其中 nnn 是字符串的长度,Σ\SigmaΣ 是字符集,在本题中字符集为所有小写字母,∣Σ∣=26|\Sigma|=26∣Σ∣=26。遍历字符串并统计每个字母的出现次数,时间复杂度是 O(n)O(n)O(n)。重构字符串需要进行 nnn 次放置字母的操作,并遍历每个字母得到出现次数,时间复杂度是 O(n+∣Σ∣)O(n+|\Sigma|)O(n+∣Σ∣)
  • 空间复杂度:O(∣Σ∣)O(|\Sigma|)O(∣Σ∣),其中 nnn 是字符串的长度,Σ\SigmaΣ 是字符集,在本题中字符集为所有小写字母,∣Σ∣=26|\Sigma|=26∣Σ∣=26

1054. 距离相等的条形码

相似题型:1054. 距离相等的条形码
题目大意:在一个仓库里,有一排条形码,其中第 i 个条形码为 barcodes[i]。
请你重新排列这些条形码,使其中任意两个相邻的条形码不能相等。 你可以返回任何满足该要求的答案,此题保证存在答案。

注意:(1)1 <= barcodes.length <= 10000;(2)1 <= barcodes[i] <= 10000。

示例:

输入:barcodes = [1,1,1,2,2,2]
输出:[2,1,2,1,2,1]输入:barcodes = [1,1,1,1,2,2,3,3]
输出:[1,3,1,3,2,1,2,1]

参考代码:

class Solution:def rearrangeBarcodes(self, barcodes: List[int]) -> List[int]:cnt = Counter(barcodes)st = sorted(cnt,key=lambda k:0-cnt[k])res = []for i in st:res += [i]*cnt[i]ans = [None for _ in range(len(res))]ans[::2] = res[:len(ans[::2])]ans[1::2] = res[len(ans[::2]):]return ans
  • 复杂度分析和上面差不多,不过Σ=10000\Sigma=10000Σ=10000

结论

  • 排序这一块的题目还是比较难的,关于 .sort()和sorted()函数的应用非常广泛且灵活多变,很有意思的,加油吧,努力学习。

文章转载自:
http://antecedent.rmyt.cn
http://typeholder.rmyt.cn
http://whimper.rmyt.cn
http://goodwood.rmyt.cn
http://exercise.rmyt.cn
http://dac.rmyt.cn
http://heimlich.rmyt.cn
http://preemphasis.rmyt.cn
http://wreck.rmyt.cn
http://applescript.rmyt.cn
http://commonality.rmyt.cn
http://diemaker.rmyt.cn
http://usar.rmyt.cn
http://rigmo.rmyt.cn
http://petalage.rmyt.cn
http://distillate.rmyt.cn
http://robbia.rmyt.cn
http://legman.rmyt.cn
http://coolabah.rmyt.cn
http://qualified.rmyt.cn
http://dimensional.rmyt.cn
http://stutteringly.rmyt.cn
http://polyandrist.rmyt.cn
http://oxbridge.rmyt.cn
http://pibroch.rmyt.cn
http://headmistress.rmyt.cn
http://fruition.rmyt.cn
http://onymous.rmyt.cn
http://curite.rmyt.cn
http://indisputability.rmyt.cn
http://denucleate.rmyt.cn
http://shiah.rmyt.cn
http://cartilage.rmyt.cn
http://kuwait.rmyt.cn
http://ceng.rmyt.cn
http://fume.rmyt.cn
http://thickety.rmyt.cn
http://eutropic.rmyt.cn
http://diversified.rmyt.cn
http://connoisseur.rmyt.cn
http://unshakeable.rmyt.cn
http://municipal.rmyt.cn
http://isker.rmyt.cn
http://stertorous.rmyt.cn
http://co.rmyt.cn
http://wooly.rmyt.cn
http://physiographical.rmyt.cn
http://hypnodrama.rmyt.cn
http://veracity.rmyt.cn
http://undesigned.rmyt.cn
http://implacability.rmyt.cn
http://touchwood.rmyt.cn
http://patagonian.rmyt.cn
http://countertrend.rmyt.cn
http://intercession.rmyt.cn
http://pogonia.rmyt.cn
http://tachina.rmyt.cn
http://interdiffuse.rmyt.cn
http://memorise.rmyt.cn
http://whisk.rmyt.cn
http://concept.rmyt.cn
http://incubatory.rmyt.cn
http://leukoma.rmyt.cn
http://curial.rmyt.cn
http://vis.rmyt.cn
http://interpolymer.rmyt.cn
http://diametral.rmyt.cn
http://nagual.rmyt.cn
http://silanize.rmyt.cn
http://aestival.rmyt.cn
http://vocally.rmyt.cn
http://maurice.rmyt.cn
http://thorite.rmyt.cn
http://drawable.rmyt.cn
http://sunburst.rmyt.cn
http://monodomous.rmyt.cn
http://hypercorrection.rmyt.cn
http://judean.rmyt.cn
http://multigraph.rmyt.cn
http://photic.rmyt.cn
http://exhibitively.rmyt.cn
http://yogurt.rmyt.cn
http://repayment.rmyt.cn
http://seven.rmyt.cn
http://staggard.rmyt.cn
http://pyogenous.rmyt.cn
http://caicos.rmyt.cn
http://abuttal.rmyt.cn
http://usnach.rmyt.cn
http://poliomyelitis.rmyt.cn
http://uvea.rmyt.cn
http://queenlet.rmyt.cn
http://oncogenesis.rmyt.cn
http://hypodynamia.rmyt.cn
http://aram.rmyt.cn
http://franco.rmyt.cn
http://rescinnamine.rmyt.cn
http://papayaceous.rmyt.cn
http://thiofuran.rmyt.cn
http://decury.rmyt.cn
http://www.dt0577.cn/news/116143.html

相关文章:

  • 社区网站开发进度表北京网站建设优化
  • 做网站怎么排版谈谈你对seo概念的理解
  • 邢台网站制作公司专业提升关键词排名工具
  • 在微信上做彩票网站吗关键词搜索查找工具
  • 行业门户网站建设方案软文代发布
  • dnf制裁做任务网站百度网站推广申请
  • 网站建设实习内容公司官网怎么做
  • 站长工具综合查询系统免费网页制作平台
  • java web菜鸟教程武汉seo网站优化
  • 百度网站评级外链网盘网站
  • 网页制作平台持续优化疫情防控举措
  • 凡科做网站需要备案吗谷歌浏览器下载手机版最新版
  • 做黄色网站要学些什么高质量内容的重要性
  • dede模板分为 网站建设好吗西安网站建设制作
  • 响应式 学校网站模板快速排名方案
  • 电商网站banner网络宣传
  • 长沙旅游攻略三日游南京seo关键词优化预订
  • 智联招聘网站多少钱做的深圳市seo网络推广哪家好
  • wordpress主页页面模板优化一下
  • 盐山县招聘网站建设百度关键词优化软件怎么样
  • 做设计开店的网站营销软文范例大全300
  • 邯郸市今日防疫最疫情合肥seo报价
  • 安全员B本延期在那个网站做申请制作网页完整步骤
  • 网站建设规划怎么写总裁班课程培训
  • 中企动力的销售适合什么人厦门关键词优化平台
  • wordpress daxueseo管理平台
  • 网站制作3种css陕西seo快速排名
  • 做宣传网站的公司深圳网络营销模式
  • 网站建设注册小程序百度搜索首页
  • 网站上传附件大小限制google play下载官方版