当前位置:网站首页>Leetcode 1385. Distance value between two arrays
Leetcode 1385. Distance value between two arrays
2022-06-29 23:21:00 【I'm not xiaohaiwa~~~~】

Here are two arrays of integers arr1 , arr2 And an integer d , Please return the... Between two arrays Distance value .
「 Distance value 」 Number of elements defined as meeting this distance requirement : For elements arr1[i] , There are no elements arr2[j] Satisfy |arr1[i]-arr2[j]| <= d .
Example 1:
Input :arr1 = [4,5,8], arr2 = [10,9,1,8], d = 2
Output :2
explain :
about arr1[0]=4 We have :
|4-10|=6 > d=2
|4-9|=5 > d=2
|4-1|=3 > d=2
|4-8|=4 > d=2
therefore arr1[0]=4 Meet the distance requirements
about arr1[1]=5 We have :
|5-10|=5 > d=2
|5-9|=4 > d=2
|5-1|=4 > d=2
|5-8|=3 > d=2
therefore arr1[1]=5 Also meet the distance requirements
about arr1[2]=8 We have :
|8-10|=2 <= d=2
|8-9|=1 <= d=2
|8-1|=7 > d=2
|8-8|=0 <= d=2
There is a distance less than or equal to 2 The situation of , Does not meet the distance requirements
So only arr1[0]=4 and arr1[1]=5 Two meet the distance requirements , The distance value is 2
Example 2:
Input :arr1 = [1,4,2,3], arr2 = [-4,-3,6,10,20,30], d = 3
Output :2
Example 3:
Input :arr1 = [2,1,100,3], arr2 = [-5,-2,10,-3,7], d = 6
Output :1
Tips :
1 <= arr1.length, arr2.length <= 500
- -10^3 <= arr1[i], arr2[j] <= 10^3
- 0 <= d <= 100
Code:
class Solution {
public:
int findTheDistanceValue(vector<int>& arr1, vector<int>& arr2, int d) {
int res=0;
for(int i=0;i<arr1.size();i++)
{
bool flag=false;
for(int j=0;j<arr2.size();j++)
{
if(abs(arr1[i]-arr2[j])<=d)
{
flag=true;
break;
}
}
if(!flag)
res++;
}
return res;
}
};
边栏推荐
- Welcome the "top ten" of the Municipal Association for science and technology • pay tribute to Lu Yi, a scientific and technological worker: an explorer guarding the transmission security of the power
- Incluxdb time series database system
- PROJECT #1 - BUFFER POOL [CMU 15-445645]笔记
- 疫情下我离职一年,收入增长了10倍
- 什么是IGMP?IGMP与ICMP有啥区别?
- Principe de réalisation de l'agent dynamique
- C language tutorial – -6 loop statement
- 80-Redis详解
- 0. grpc环境搭建
- Polymorphism of laravel association model
猜你喜欢

M1笔记本居家办公的痛点及解决方案 | 社区征文

开源了 | 文心大模型ERNIE-Tiny轻量化技术,又准又快,效果全开

Procurement intelligence is about to break out, and the "3+2" system of Alipay helps enterprises build core competitive advantages
discrete "digital signal"]"/>Speech signal processing (III): speech signal analysis [continuous "analog signal" -- Sampling, quantization, coding -- > discrete "digital signal"]

架构实战营模块 5 作业

正则表达式:字符(2)

InfluxDB时序数据库系统

2022年PMP项目管理考试敏捷知识点(5)

Go zero micro Service Practice Series (VII. How to optimize such a high demand)

Design of Distributed Message Oriented Middleware
随机推荐
架构实战营模块 5 作业
constexpr 函数
Gracefully transform the SMS business module and start the strategic mode!
关于二叉树
C指针进阶2-->函数指针数组 回调函数简化计算器代码,基于回调函数模拟实现qsort函数
redis客户端
自己收藏的一些网址
Incluxdb time series database system
Laravel 创建自己的 Facade 扩展 geoip 根据 IP 获取国家、地域、城市信息
Intranet penetration (NC)
Software testing interface testing JMeter 5.5 installation tutorial
Talk about auto in MySQL in detail_ What is the function of increment
Paper writing tool: latex online website
Error: c2665: "qmessagebox:: critical": none of the four overloads can convert all parameter types
Wechat applet: big red festive UI guessing lantern riddles is also called guessing character riddles
微博系统中”微博评论“的高性能高可用计算架构
STM32 basic knowledge points
Vs cannot locate program input point to DLL
STM32基础知识点
js函数相关的复习