1. 程式人生 > >383. Ransom Note 在字典數組中查找筆記數組

383. Ransom Note 在字典數組中查找筆記數組

字典 int ted 結構 each exit let 一句話 英文

[抄題]:

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 在字典數組中查找筆記數組