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 |
Tags
- 자바
- database
- Data Structure
- Class
- 파이썬
- Tree
- dynamic programming
- Stack
- 구현
- 코테
- implement
- bit manipulation
- two pointers
- geometry
- SQL
- Math
- Number Theory
- array
- hash table
- java
- Method
- Binary Tree
- Binary Search
- simulation
- Counting
- greedy
- sorting
- 코딩테스트
- string
- Matrix
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 1365. How Many Numbers Are Smaller Than the Current Number 본문
코딩테스트 풀이/JAVA
[LeetCode/Easy] 1365. How Many Numbers Are Smaller Than the Current Number
무지맘 2022. 12. 24. 02:181. Input
1) 정수 배열 nums
2. Output
1) nums[i] = (nums[i]보다 작은 요소의 개수)로 치환한 배열
2) 이때 자기 자신을 제외한 나머지 요소만 비교한다.
3. Constraint
1) 2 <= nums.length <= 500
2) 0 <= nums[i] <= 100
4. Example
Input: nums = [8,1,2,2,3] -> Output: [4,0,1,1,3]
설명:
- index 0: 8보다 작은 수는 4개
- index 1: 1보다 작은 수는 0개
- index 2: 2보다 작은 수는 1개
- index 3: 2보다 작은 수는 1개
- index 4: 3보다 작은 수는 3개
- 따라서 [4,0,1,1,3]을 반환한다.
5. Code
1) 첫 코드(2022/06/03)
int len = nums.length;
int[] ans = new int[len];
int n;
for(int i=0 ; i<len ; i++){
n = nums[i];
for(int j=0 ; j<len ; j++){
if(nums[j] < n) ans[i]++;
} // for j
} // for i
return ans;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 1389. Create Target Array in the Given Order (0) | 2022.12.24 |
---|---|
[LeetCode/Easy] 1385. Find the Distance Value Between Two Arrays (0) | 2022.12.24 |
[LeetCode/Easy] 1351. Count Negative Numbers in a Sorted Matrix (0) | 2022.12.24 |
[LeetCode/Easy] 1346. Check If N and Its Double Exist (0) | 2022.12.24 |
[LeetCode/Easy] 1342. Number of Steps to Reduce a Number to Zero (0) | 2022.12.24 |