LoginSignup
0
0

383. Ransom Note

Posted at

383. Ransom Note

magazineの文字列がransomNoteで構成されているかどうかのチェックだった気がする。。
辞書型の復習

class Solution:
    def canConstruct(self, ransomNote: str, magazine: str) -> bool:
        wordDict = {}
        for i in ransomNote:
            wordDict[i]=ransomNote.count(i)
            ransomNote.replace(i,"")
        counter = 0
        for i in wordDict:
            if(i not in magazine or magazine.count(i) < wordDict[i]):
                counter += 1
        if(counter == 0):
            return 1
        else:
            return 0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0