当前位置:网站首页>Leetcode383 ransom letter
Leetcode383 ransom letter
2022-07-27 22:19:00 【Peihj2021】
leetcode383 Ransom letter
Topic link :leetcode
Thought analysis
The letters in the title are all lowercase characters , So we consider using arrays to map using hash algorithm , We will magazine Array mapping , Add it at the specified position 1.
And then we went to randomNote Traversal , Subtract one from the mapped position , Finally, let's see if there is less than 0 It's a good number , If there is less than 0 It proves that there are other elements in the array , That's not right , Go straight back to false, If there is no less than 0 Yes, then go back true.
Code
class Solution {
public boolean canConstruct(String ransomNote, String magazine) {
int[] nums = new int[26];
for (int i = 0; i < magazine.length(); i++) {
nums[magazine.charAt(i) - 'a'] += 1;
}
for (int i = 0; i < ransomNote.length(); i++) {
nums[ransomNote.charAt(i) - 'a'] -= 1;
}
for (int num : nums) {
if (num < 0){
return false;
}
}
return true;
}
}
边栏推荐
- Wechat applet live broadcast plug-in -- get temporary files (background integrated applet live broadcast)
- 【无标题】
- How to buy stocks on mobile phones? Is it safe to open an account
- First knowledge of esp8266 (I) -- access point and wireless terminal mode
- STM32项目分享---MQTT智能门禁系统(含APP控制)
- Behind every piece of information you collect, you can't live without TA
- JVM memory model interview summary
- @Can component be used on the same class as @bean?
- Matplotlib 多子图绘制
- B站崩了,如果我们是那晚负责修复的开发人员
猜你喜欢

一种比读写锁更快的锁,还不赶紧认识一下

Is log4j vulnerability still widespread?

【图解】三次握手,四次挥手 —— 用心看这一篇就够了

It's too voluminous. A company has completely opened its core system (smart system) that has been operating for many years

Implementation of arbitrary code execution based on.Net dynamic compilation technology

Exception -exception

Seven lines of code crashed station B for three hours
![[question 23] Sudoku game with rotation | DFS (Beijing Institute of Technology / Beijing Institute of Technology / programming methods and practice / primary school)](/img/75/c207f4f562fd5b547c5b3134113154.jpg)
[question 23] Sudoku game with rotation | DFS (Beijing Institute of Technology / Beijing Institute of Technology / programming methods and practice / primary school)

8000字讲透OBSA原理与应用实践

B站崩了,如果我们是那晚负责修复的开发人员
随机推荐
It's too voluminous. A company has completely opened its core system (smart system) that has been operating for many years
固体继电器
Excel only wants to visualize charts and make data move? Yes, come and watch (with a large number of templates to download)
Mimx8md6cvahzab i.MX 8mdual cortex-a53 - Microprocessor
Lvs+kept highly available cluster
[numerical analysis exercise] Jacobi iteration method of third-order matrix
leetcode383赎金信
SQL注入 Less26a(布尔盲注)
dBm和Vpp以及Vpeak的关系
【StoneDB故障诊断】系统资源瓶颈诊断
一种比读写锁更快的锁,还不赶紧认识一下
视频直播源码,uni-app实现广告滚动条
Apachespark command execution (cve-2022-33891) vulnerability recurrence
Is it safe to open an account online now? Then choose which securities to open a securities account
Inertial navigation principle (VII) -imu error classification (II) -allan variance analysis method +imu test + calibration introduction
Matplotlib multi subgraph drawing
Can JVM tuning be done with single core CPU and 1G memory?
How can anyone ask how MySQL archives data?
Leetcode-155-minimum stack
Open source data quality solution -- Apache Griffin primer