当前位置:网站首页>14 检查整数及其两倍数是否存在
14 检查整数及其两倍数是否存在
2022-07-17 00:07:00 【DHU杨骅麟(紫外线过敏)】
14 检查整数及其两倍数是否存在
作者: Turbo时间限制: 1S章节: 课程设计
问题描述 :
给你一个整数数组 arr,请你检查是否存在两个整数 N 和 M,满足 N 是 M 的两倍(即,N == 2 * M)。
更正式地,检查是否存在两个下标 i 和 j 满足:
i != j
0 <= i, j < arr.length
arr[i] == 2 * arr[j]
示例 1:
输入:
4
10 2 5 3
输出:true
解释:N = 10 是 M = 5 的两倍,即 10 = 2 * 5 。
示例 2:
输入:
4
7 1 14 11
输出:true
解释:N = 14 是 M = 7 的两倍,即 14 = 2 * 7 。
示例 3:
输入:
4
3 1 7 11
输出:false
解释:在该情况下不存在 N 和 M 满足 N = 2 * M 。
输入说明 :
输入两行:
第一行输入一个整数n表示数组arr的长度。
第二行输入n个整数表示数组的元素。
提示:
2 <= n <= 500
-10^3 <= arr[i] <= 10^3
输出说明 :
输出一个布尔值true或false表示结果。
输入范例 :
4
2 4 5 7
输出范例 :
true
又是一道要用哈希表(自认为是哈希数组)的题目 借助辅助数组 来方便判断。
#include<iostream>
using namespace std;
int main()
{
int arr[1000] = { 0 };
int haxi[1000] = { 0 };
int n = 0;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i];
haxi[arr[i]]++;
}
for (int i = 0; i < n; i++)
{
if (haxi[2 * arr[i]] > 0)
{
cout << "true";
return 0;
}
}
cout << "false";
return 0;
}边栏推荐
猜你喜欢

Assemblage stylisé de cartes de commutation auto - encapsulées

软件漏洞分析入门(四)

使用redis - zset做排行榜
![[elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]](/img/73/af7ca3f670ffee18081b9ca6a9ccf6.png)
[elementui El date picker date selector, the end time must not be earlier than the start time, and only the date of the specified number of days from the start time can be selected]

Summary of Applied Cryptography

XSS simple summary

XXX packages are looking for funding run `npm fund` for details解决方法

uni-app微信小程序——商城(4)——商家

uni-app微信小程序——商城(3)——商城主页

页面布局——三栏布局解决方式
随机推荐
(6) Test command
js截取字符串前几位或者截取字符串后几位
Express中间件的分类及使用
Uniapp calls the map to query the location and mark the location
mock平台的使用说明
three.js初体验:模拟一个小树杈的生长
Deployment of cobalstrike (with resources)
软件漏洞分析入门(五)
页面布局——三栏布局解决方式
02_ Data binding
Uni app wechat applet - Mall (3) - Mall Homepage
[GFCTF 2021]Baby_ Cve-2021-41773 on the web
Summary of XML external entity injection (xxE target recurrence)
Common methods of JS array
JS replaces a character in the string, and JS modifies the specified character in the string
Es optional chain
今天的码农女孩总结了关于npm包管理和url模块的笔记
iptables和snort基本配置
Cve-2022-34265 Django extract & TRUNC SQL injection vulnerability recurrence
Array Operations - judgment, de duplication, consolidation, expansion