码迷,mamicode.com
首页 > 编程语言 > 详细

383. Ransom Note 在字典数组中查找笔记数组

时间:2018-03-19 13:35:26      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:false   代码   题目   .com   情况   int   解法   不用   other   

[抄题]:

Given an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom note can be constructed from the magazines ; otherwise, it will return false. 

Each letter in the magazine string can only be used once in your ransom note.

Note:
You may assume that both strings contain only lowercase letters.

canConstruct("a", "b") -> false
canConstruct("aa", "ab") -> false
canConstruct("aa", "aab") -> true

 [暴力解法]:

时间分析:

空间分析:

 [优化后]:

时间分析:

空间分析:

[奇葩输出条件]:

[奇葩corner case]:

[思维问题]:

以为要查找note的起点、终点:没必要,太麻烦,不如遍历,表示每个字母都给查

[一句话思路]:

[输入量]:空: 正常情况:特大:特小:程序里处理到的特殊情况:异常情况(不合法不合理的输入):

[画图]:

技术分享图片

[一刷]:

[二刷]:

[三刷]:

[四刷]:

[五刷]:

  [五分钟肉眼debug的结果]:

[总结]:

[复杂度]:Time complexity: O() Space complexity: O()

[英文数据结构或算法,为什么不用别的数据结构或算法]:

int[26]虽然是数字的数组,但是可以统计字母出现的次数,字符串题常用

[关键模板化代码]:

[其他解法]:

[Follow Up]:

[LC给出的题目变变变]:

 [代码风格] :

383. Ransom Note 在字典数组中查找笔记数组

标签:false   代码   题目   .com   情况   int   解法   不用   other   

原文地址:https://www.cnblogs.com/immiao0319/p/8601093.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!