当前位置:网站首页>Daily 3 questions (3) - check whether integers and their multiples exist
Daily 3 questions (3) - check whether integers and their multiples exist
2022-06-25 10:48:00 【Programmed ape without hair loss 2】
subject :
Give you an array of integers arr, Please check whether there are two integers N and M, Satisfy N yes M Twice as many ( namely ,N = 2 * M).
More formally , Check if there are two subscripts i and j Satisfy :
i != j
0 <= i, j < arr.length
arr[i] == 2 * arr[j]
Example 1:
Input :arr = [10,2,5,3]
Output :true
explain :N = 10 yes M = 5 Twice as many , namely 10 = 2 * 5 .
Example 2:
Input :arr = [7,1,14,11]
Output :true
explain :N = 14 yes M = 7 Twice as many , namely 14 = 2 * 7 .
Example 3:
Input :arr = [3,1,7,11]
Output :false
explain : Does not exist in this case N and M Satisfy N = 2 * M .
Tips :
2 <= arr.length <= 500
-10^3 <= arr[i] <= 10^3
Ideas :
Store all the numbers in the hash table first , Then traverse all the numbers xx, Judge 2x2x Whether it is in the hash table .
java Code :
class Solution {
public boolean checkIfExist(int[] arr) {
HashSet<Integer> set = new HashSet<>();
for (int i : arr) {
if (set.contains(2 * i) || (i % 2 == 0 && set.contains(i / 2)))
return true;
set.add(i);
}
return false;
}
}
边栏推荐
- tokenizers>=0.11.1,!= 0.11.3,<0.13 is required for a normal functioning of this module,
- After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-7
- [200 opencv routines] 210 Are there so many holes in drawing a straight line?
- IdentityServer4 定义概念
- 【系统分析师之路】第六章 复盘需求工程(综合知识概念)
- The real difference between i++ and ++i
- Google Earth engine (GEE) - evaluate enables one click batch download of all single images in the research area (some areas in Shanghai)
- 【RPC】I/O模型——BIO、NIO、AIO及NIO的Rector模式
- Garbage collection mechanism
- Create menu file
猜你喜欢
[dynamic planning] - Digital triangle
This is enough for request & response
P2P network core technology: Gossip protocol
[paper reading | deep reading] line: large scale information network embedding
Flask blog practice - realize the latest articles and search in the sidebar
Mqtt beginner level chapter
What is CRA
我希望按照我的思路盡可能將canvas基礎講明白
戴尔科技演绎“快”字诀,玩转CI/CD
Kotlin arrays and collections (1) {create arrays, use arrays, use for in loops to traverse arrays, use array indexes, and multi-dimensional arrays}
随机推荐
[paper reading | deep reading] line: large scale information network embedding
我希望按照我的思路盡可能將canvas基礎講明白
Sign up to open the third session of the "flying oar hacker marathon". It's been a long time
【图像融合】基于形态学分析结合稀疏表征实现图像融合附matlab代码
Mqtt beginner level chapter
Handling of NPM I installation problems
Unreal Engine graphics and text notes: use VAT (vertex animation texture) to make Houdini end on Houdini special effect (ue4/ue5)
Flask blog practice - realize personal center and authority management
撸一个随机数生成器
Ouverture de l'inscription | le troisième marathon des hackers de pagaie est arrivé comme prévu.
Tutorial on installing SSL certificates in Microsoft Exchange Server 2007
報名開啟|飛槳黑客馬拉松第三期如約而至,久等啦
[observation] objectscale: redefining the next generation of object storage, reconstruction and innovation of Dell Technology
1-7Vmware中的快照与克隆
Software testing to avoid being dismissed during the probation period
Is it safe to open an account through mobile phone if you open an account through stock speculation? Who knows?
Network protocol learning -- lldp protocol learning
学会自学【学会学习本身,比学什么都重要】
[image fusion] image fusion based on morphological analysis and sparse representation with matlab code
宏的运用接续符\