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 |
Tags
- Binary Search
- 코딩테스트
- Stack
- simulation
- implement
- 코테
- Data Structure
- 자바
- Tree
- Number Theory
- Method
- geometry
- Matrix
- java
- two pointers
- 구현
- 파이썬
- Counting
- Class
- sorting
- Binary Tree
- greedy
- database
- string
- dynamic programming
- array
- bit manipulation
- hash table
- Math
- SQL
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1995. Count Special Quadruplets 본문
1. Input
1) 정수 배열 nums
2. Output
1) 다음 조건을 만족하는 4개 숫자의 쌍의 개수를 반환
// 조건
- nums[a] + nums[b] + nums[c] == nums[d]
- a < b < c < d
3. Constraint
1) 4 <= nums.length <= 50
2) 1 <= nums[i] <= 100
4. Example
Input: nums = [1,1,1,3,5] -> Output: 4
설명:
- index(0, 1, 2, 3): 1 + 1 + 1 == 3
- index(0, 1, 3, 4): 1 + 1 + 3 == 5
- index(0, 2, 3, 4): 1 + 1 + 3 == 5
- index(1, 2, 3, 4): 1 + 1 + 3 == 5
5. Code
1) 첫 코드(2022/08/03)
int count = 0;
for(int a=0 ; a<nums.length-3 ; a++)
for(int b=a+1 ; b<nums.length-2 ; b++)
for(int c=b+1 ; c<nums.length-1 ; c++)
for(int d=c+1 ; d<nums.length ; d++)
if(nums[a] + nums[b] + nums[c] == nums[d])
count++;
return count;
- 더 좋은 방법이 없을까..
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2006. Count Number of Pairs With Absolute Difference K (0) | 2023.01.11 |
---|---|
[LeetCode/Easy] 2000. Reverse Prefix of Word (0) | 2023.01.09 |
[LeetCode/Easy] 1991. Find the Middle Index in Array (0) | 2023.01.09 |
[LeetCode/Easy] 1979. Find Greatest Common Divisor of Array (0) | 2023.01.09 |
[LeetCode/Easy] 1967. Number of Strings That Appear as Substrings in Word (0) | 2023.01.09 |