当前位置:网站首页>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
magazine
The letters inside make upransonNote
, Letters cannot be reused - 2. First of all, will
magazine
Build a dictionary with the letters and occurrences instr1
- 3. Then start traversing
ransonNote
Letters in , If you encountermagazine
Letters not in , That is to saystr1
Key values that do not exist in , Then return directlyFalse
- 4. Each time from
str1
Take out a letter fromransonNote
when , takestr1
The number of occurrences of the letter in is reduced by one , Whenstr1
The number of occurrences of letters in is less than 0 when , explainmagazine
The 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
边栏推荐
- Unipolar NRZ code, bipolar NRZ code, 2ASK, 2FSK, 2PSK, 2DPSK and MATLAB simulation
- [BIM introduction practice] Revit building wall: detailed picture and text explanation of structure, envelope and lamination
- Brushless motor drive scheme based on Infineon MCU GTM module
- Effects of antibiotics on microbiome and human health
- Single chip microcomputer serial port data processing (2) -- ucosiii + cyclic queue receiving data
- SQL statement for adding columns in MySQL table
- [AI vision · quick review of today's sound acoustic papers, issue 2] Fri, 15 APR 2022
- Stm32f4 MCU ADC sampling and FFT of ARM-DSP Library
- Redis 命令大全
- Network principle | connection management mechanism in TCP / IP important protocol and core mechanism
猜你喜欢
Jetpack 之 LifeCycle 组件使用详解
AWS EKS添加集群用户或IAM角色
Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
小红书被曝整体裁员20%,大厂之间内卷也很严重
matlab讀取多張fig圖然後合並為一張圖(子圖的形式)
Iron and intestinal flora
Qtspim manual - Chinese Translation
Installation du compilateur croisé de la plateforme zynq
Stm32f4 MCU ADC sampling and FFT of ARM-DSP Library
Supplément: annotation
随机推荐
【BIM+GIS】ArcGIS Pro2.8如何打开Revit模型,BIM和GIS融合?
As a code farmer, what kind of experience is it that a girlfriend can code better than herself?
Express middleware ② (classification of Middleware)
HMS Core Discovery第14期回顾长文|纵享丝滑剪辑,释放视频创作力
Inverse system of RC low pass filter
【Pytorch基础】torch.split()用法
STM32F4单片机ADC采样及ARM-DSP库的FFT
Unipolar NRZ code, bipolar NRZ code, 2ASK, 2FSK, 2PSK, 2DPSK and MATLAB simulation
Basic use of shell WC (counting the number of characters)
优麒麟 22.04 LTS 版本正式发布 | UKUI 3.1开启全新体验
用D435i录制自己的数据集运行ORBslam2并构建稠密点云
Detailed explanation of life cycle component of jetpack
[AI vision · quick review of robot papers today, issue 32] wed, 20 APR 2022
Understand the gut organ axis, good gut and good health
MYSQL50道基础练习题
1个需求的一生,团队协作在云效钉钉小程序上可以这么玩
[echart] démarrer avec echart
【测绘程序设计】坐标方位角推算神器(C#版)
单片机串口数据处理(2)——uCOSIII+循环队列接收数据
Supplement: Annotation