JAVA_LeetCode 1385_Find the Distance Value Between Two Arrays


JAVA_LeetCode 1385_Find the Distance Value Between Two Arrays

JAVA_LeetCode 1385_Find the Distance Value Between Two Arrays 풀이 class Solution { public int findTheDistanceValue(int[] arr1, int[] arr2, int d) { // 두 배열요소의 차이가 d보다 같거나 작은 경우, 거리값을 추가한다. int cnt = 0; for(int i = 0; i < arr1.length; i++){ for(int j = 0; j < arr2.length; j++){ if (Math.abs(arr1[i] - arr2[j]) <= d) { cnt++; break; } } } // arr1 길이에서 거리값이 존재한 요소를 뺀 값을 반환한다. return arr1.length - cnt; } } 문제 설명이 좀 이상한거 같은데, 예시에선 두 배열의 차이의 절대값이 특정 값보다 같거나 작아야한다는점이 문제설명과 좀 다르게 보였었는데.. 앞 배열에서 거리값이 존재한 요...


#JAVA #JAVA_FindtheDistanceValueBetweenTwoArrays #JAVA_LeetCode1385 #JAVA_LeetCode1385_FindtheDistanceValueBetweenTwoArrays #LeetCode1385_FindtheDistanceValueBetweenTwoArrays

원문링크 : JAVA_LeetCode 1385_Find the Distance Value Between Two Arrays