Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- 구현
- dynamic programming
- 파이썬
- java
- 자바
- Binary Search
- Stack
- Tree
- 코테
- array
- Number Theory
- Class
- sorting
- implement
- greedy
- Counting
- bit manipulation
- hash table
- SQL
- 코딩테스트
- Math
- Matrix
- simulation
- Data Structure
- two pointers
- Method
- geometry
- string
- Binary Tree
- database
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 2006. Count Number of Pairs With Absolute Difference K 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 2006. Count Number of Pairs With Absolute Difference K
무지맘 2023. 1. 11. 00:341. Input
1) 정수 배열 nums
2) 정수 k
2. Output
1) i<j이고 |nums[i]-nums[j]|==k인 (i, j)쌍의 개수를 반환
3. Constraint
1) 1 <= nums.length <= 200
2) 1 <= nums[i] <= 100
3) 1 <= k <= 99
4. Example
Input: nums = [1,2,2,1], k = 1 -> Output: 4
설명:
- nums[0]==1, nums[1]==2
- nums[0]==1, nums[2]==2
- nums[1]==2, nums[3]==1
- nums[2]==2, nums[3]==1
5. Code
1) 첫 코드(2022/06/05)
int count = 0;
for(int i=0 ; i<nums.length-1 ; i++){
for(int j=i+1 ; j<nums.length ; j++){
if(Math.abs(nums[i] - nums[j]) == k)
count++;
} // for j
} // for i
return count;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2016. Maximum Difference Between Increasing Elements (0) | 2023.01.11 |
---|---|
[LeetCode/Easy] 2011. Final Value of Variable After Performing Operations (0) | 2023.01.11 |
[LeetCode/Easy] 2000. Reverse Prefix of Word (0) | 2023.01.09 |
[LeetCode/Easy] 1995. Count Special Quadruplets (0) | 2023.01.09 |
[LeetCode/Easy] 1991. Find the Middle Index in Array (0) | 2023.01.09 |