Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 610d669

Browse files
committedApr 12, 2025
Add solution #1385
1 parent e8db09e commit 610d669

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed
 

‎README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1,268 LeetCode solutions in JavaScript
1+
# 1,269 LeetCode solutions in JavaScript
22

33
[https://leetcodejavascript.com](https://leetcodejavascript.com)
44

@@ -1055,6 +1055,7 @@
10551055
1381|[Design a Stack With Increment Operation](./solutions/1381-design-a-stack-with-increment-operation.js)|Medium|
10561056
1382|[Balance a Binary Search Tree](./solutions/1382-balance-a-binary-search-tree.js)|Medium|
10571057
1383|[Maximum Performance of a Team](./solutions/1383-maximum-performance-of-a-team.js)|Hard|
1058+
1385|[Find the Distance Value Between Two Arrays](./solutions/1385-find-the-distance-value-between-two-arrays.js)|Easy|
10581059
1389|[Create Target Array in the Given Order](./solutions/1389-create-target-array-in-the-given-order.js)|Easy|
10591060
1400|[Construct K Palindrome Strings](./solutions/1400-construct-k-palindrome-strings.js)|Medium|
10601061
1402|[Reducing Dishes](./solutions/1402-reducing-dishes.js)|Hard|
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* 1385. Find the Distance Value Between Two Arrays
3+
* https://leetcode.com/problems/find-the-distance-value-between-two-arrays/
4+
* Difficulty: Easy
5+
*
6+
* Given two integer arrays arr1 and arr2, and the integer d, return the distance value between
7+
* the two arrays.
8+
*
9+
* The distance value is defined as the number of elements arr1[i] such that there is not any
10+
* element arr2[j] where |arr1[i]-arr2[j]| <= d.
11+
*/
12+
13+
/**
14+
* @param {number[]} arr1
15+
* @param {number[]} arr2
16+
* @param {number} d
17+
* @return {number}
18+
*/
19+
var findTheDistanceValue = function(arr1, arr2, d) {
20+
let result = 0;
21+
22+
for (const num1 of arr1) {
23+
let isValid = true;
24+
for (const num2 of arr2) {
25+
if (Math.abs(num1 - num2) <= d) {
26+
isValid = false;
27+
break;
28+
}
29+
}
30+
if (isValid) result++;
31+
}
32+
33+
return result;
34+
};

0 commit comments

Comments
 (0)
Please sign in to comment.