当前位置:网站首页>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
边栏推荐
- STM32F4单片机ADC采样及ARM-DSP库的FFT
- 重剑无锋,大巧不工
- QML进阶(四)-绘制自定义控件
- MYSQL查询至少连续n天登录的用户
- Detailed explanation of life cycle component of jetpack
- 【BIM+GIS】ArcGIS Pro2.8如何打开Revit模型,BIM和GIS融合?
- matlab讀取多張fig圖然後合並為一張圖(子圖的形式)
- 补充番外14:cmake实践项目笔记(未完待续4/22)
- What is software acceptance testing? What are the benefits of acceptance testing conducted by third-party software testing institutions?
- Matlab minimalist configuration of vscode configuration
猜你喜欢
How to regulate intestinal flora? Introduction to common natural substances, probiotics and prebiotics
Express中间件②(中间件的分类)
兼容NSR20F30NXT5G的小体积肖特基二极管
Go反射法则
补充番外14:cmake实践项目笔记(未完待续4/22)
Jetpack 之 LifeCycle 组件使用详解
STM32单片机ADC规则组多通道转换-DMA模式
无线键盘全国产化电子元件推荐方案
【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
Coinbase: basic knowledge, facts and statistics about cross chain bridge
随机推荐
【时序】基于 TCN 的用于序列建模的通用卷积和循环网络的经验评估
Installation and use of Apache bench (AB pressure test tool)
Unipolar NRZ code, bipolar NRZ code, 2ASK, 2FSK, 2PSK, 2DPSK and MATLAB simulation
VHDL语言实现32位二进制数转BCD码
Shopping mall for transportation tools based on PHP
VHDL implementation of 32-bit binary to BCD code
Use recyclerview to realize left-right side-by-side classification selection
Detailed explanation of life cycle component of jetpack
KVM error: Failed to connect socket to ‘/var/run/libvirt/libvirt-sock‘
Go反射法则
php导出Excel表格
Chapter 4 - understanding standard equipment documents, filters and pipelines
MYSQL查询至少连续n天登录的用户
智能电子秤全国产化电子元件推荐方案
Xiaohongshu was exposed to layoffs of 20% as a whole, and the internal volume among large factories was also very serious
Express middleware ② (classification of Middleware)
IEEE Transactions on Industrial Informatics(TII)投稿须知
Summary of Android development posts I interviewed in those years (attached test questions + answer analysis)
Iron and intestinal flora
mysql ,binlog 日志查询