로딩
요청 처리 중입니다...

JAVA_LeetCode 2367_Number of Arithmetic Triplets

 JAVA_LeetCode 2367_Number of Arithmetic Triplets

JAVA_LeetCode 2367_Number of Arithmetic Triplets 풀이 class Solution { public int arithmeticTriplets(int[] nums, int diff) { // 중복값을 제거, 요소에서 diff를 더한값과 2 * diff가 있는 경우를 체크한다. Set set = new HashSet(); int cnt = 0; for(int num : nums) set.add(num); for(int num : nums){ if(set.contains(num + diff) && set.contains(num + (2 * diff))) cnt++; } return cnt; } } 삼중항의 조건에 맞추기 위해 num에 diff더한값과 diff 2번을 더한값이 포함된경우를 체크한다. * 출처 https://leetcode.com/problems/number-of-arithmetic-triplets...

# JAVA # JAVA_LeetCode2367 # JAVA_LeetCode2367_NumberofArithmeticTriplets # JAVA_NumberofArithmeticTriplets # LeetCode2367_NumberofArithmeticTriplets