当前位置:网站首页>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;
}
}
边栏推荐
- 1-7Vmware中的快照与克隆
- 报名开启|飞桨黑客马拉松第三期如约而至,久等啦
- Binder explanation of Android interview notes
- Identityserver4 definition concept
- 2022-06-24:golang选择题,以下golang代码输出什么?A:1;B:3;C:4;D:编译失败。 package main import ( “fmt“ ) func mai
- Nuxtjs actual combat case
- Google Earth Engine(GEE)——evaluate實現一鍵批量下載研究區內的所有單張影像(上海市部分區域)
- 【历史上的今天】6 月 24 日:网易成立;首届消费电子展召开;世界上第一次网络直播
- Checking whether the double value is an integer - Swift - checking if a double value is an integer - swift
- 1-7snapshots and clones in VMWare
猜你喜欢

浅谈二叉树

On binary tree

虚幻引擎图文笔记:使用VAT(Vertex Aniamtion Texture)制作破碎特效(Houdini,UE4/UE5)上 Houdini端

Flask blog practice - archiving and labeling of sidebar articles

【文件包含漏洞-04】经典面试题:已知某网站仅存在本地文件包含漏洞时,如何GetShell?

Network protocol learning -- lldp protocol learning

MCU development -- face recognition application based on esp32-cam

The title of my composition is - "my district head father"

Request&Response有这一篇就够了

【OpenCV 例程200篇】210. 绘制直线也会有这么多坑?
随机推荐
Dell technology performs the "fast" formula and plays ci/cd
XSS攻击
P2P network core technology: Gossip protocol
Summary of considerations for native applet development
Google Earth Engine(GEE)——evaluate实现一键批量下载研究区内的所有单张影像(上海市部分区域)
Sign up to open the third session of the "flying oar hacker marathon". It's been a long time
撸一个随机数生成器
我希望按照我的思路盡可能將canvas基礎講明白
keep-alive
Daily Mathematics Series 52: February 20
Google Earth Engine(GEE)——evaluate實現一鍵批量下載研究區內的所有單張影像(上海市部分區域)
報名開啟|飛槳黑客馬拉松第三期如約而至,久等啦
Mqtt beginner level chapter
【动态规划】—— 数字三角形
【论文阅读|深度】Role-based network embedding via structural features reconstruction with degree-regularized
The real difference between i++ and ++i
Houdini图文笔记:Your driver settings have been set to force 4x Antialiasing in OpenGL applications问题的解决
Is it safe to open an account with Guangzhou securities by mobile phone?
How to install SSL certificates in Microsoft Exchange 2010
Software testing to avoid being dismissed during the probation period