文巾解题383. 赎金信
生活随笔
收集整理的這篇文章主要介紹了
文巾解题383. 赎金信
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 題目描述
?2? 解題思路
2.1 遍歷 ransomNote
如果這個字符在magazine中有的話,那將magazine中的這個字符remove掉,如果沒有的話就是False
class Solution:def canConstruct(self, ransomNote: str, magazine: str) -> bool:ransomNote=list(ransomNote)magazine=list(magazine)for i in ransomNote:if i in magazine:magazine.remove(i)else:return Falsereturn True2.2 查看每個字符出現的次數
如果ransomNote 中某個字符出現的次數比magazine中多的話,就是False
python庫整理: Collections.Counter_UQI-LIUWJ的博客-CSDN博客
?
?
總結
以上是生活随笔為你收集整理的文巾解题383. 赎金信的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python笔记:Gurobipy
- 下一篇: 文巾解题 372. 超级次方