当前位置:网站首页>383. Ransom letter
383. Ransom letter
2022-04-23 04:32:00 【Zhang Joshua】
383. Ransom letter
- Question no : Power button 383
- Knowledge point : Hash , Count
- Goal completion :22/150
- summary
stem :

Ideas :
- 1. Interpretation of the question : Judge whether it can be used
magazineThe letters inside make upransonNote, Letters cannot be reused - 2. First of all, will
magazineBuild a dictionary with the letters and occurrences instr1 - 3. Then start traversing
ransonNoteLetters in , If you encountermagazineLetters not in , That is to saystr1Key values that do not exist in , Then return directlyFalse - 4. Each time from
str1Take out a letter fromransonNotewhen , takestr1The number of occurrences of the letter in is reduced by one , Whenstr1The number of occurrences of letters in is less than 0 when , explainmagazineThe letters in have been reused , returnFalse
class Solution:
def canConstruct(self, ransomNote: str, magazine: str) -> bool:
str1 = {
}
str2 = {
}
for i in range(len(magazine)):
if magazine[i] in str1:
str1[magazine[i]] += 1
else:
str1[magazine[i]] = 1
for j in range(len(ransomNote)):
if ransomNote[j] in str1:
str1[ransomNote[j]] -= 1
if str1[ransomNote[j]] < 0:
return False
else:
return False
return True
版权声明
本文为[Zhang Joshua]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230415046422.html
边栏推荐
- IDE Idea 自动编译 与 On Upate Action 、 On Frame Deactivation 的配置
- 补:注解(Annotation)
- C语言: 指针的进阶
- [mapping program design] coordinate inverse artifact v1 0 (with C / C / VB source program)
- 上海航芯技术分享 | ACM32 MCU安全特性概述
- What is the thirty-six plan
- 为什么推荐你学嵌入式
- Network principle | connection management mechanism in TCP / IP important protocol and core mechanism
- 指纹Key全国产化电子元件推荐方案
- mysql table 中增加列的SQL语句
猜你喜欢

【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?

Supplément: annotation

第四章 --- 了解标准设备文件、过滤器和管道

Nature medicine reveals individual risk factors of coronary artery disease

Gut liver axis: host microbiota interaction affects hepatocarcinogenesis

协程与多进程的完美结合

Coinbase:关于跨链桥的基础知识、事实和统计数据
![[echart] Introduction to echart](/img/40/e057f4ac07754fe6f3500f3dc72293.jpg)
[echart] Introduction to echart

HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力

Supplement: Annotation
随机推荐
[AI vision · quick review of today's sound acoustic papers, issue 3] wed, 20 APR 2022
Supplement: Annotation
基于英飞凌MCU GTM模块的无刷电机驱动方案开源啦
HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力
Why recommend you to study embedded
STM32 upper μ C / shell transplantation and Application
Go 语言中的 logger 和 zap 日志库
Gut liver axis: host microbiota interaction affects hepatocarcinogenesis
【测绘程序设计】坐标反算神器V1.0(附C/C#/VB源程序)
洛谷P1858 【多人背包】 (背包求前k优解)
1个需求的一生,团队协作在云效钉钉小程序上可以这么玩
为什么推荐你学嵌入式
Go反射法则
Installation of zynq platform cross compiler
Alibaba cloud IOT transfer to PostgreSQL database scheme
Xiaohongshu was exposed to layoffs of 20% as a whole, and the internal volume among large factories was also very serious
C语言:恶搞小游戏
VHDL语言实现32位二进制数转BCD码
The difference between lists, tuples, dictionaries and collections
Basic use of shell WC (counting the number of characters)