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
- 취미
- 지쿠악스
- javascript
- 지리데칼
- 미앤아이
- 밥무하마드
- 건담헤드
- 맛집
- 바질토마토뭐시기
- DIY
- 코딩테스트
- 롱라이플
- 제프딕슨
- 발더스모드
- 발더스게이트
- LeetCode
- 코테
- 노노그램
- 프라모델
- 눈알빠지겠네
- 30mf
- 블라인드박스
- 누룽지소금빵
- 포켓몬
- 가챠
- 우리시대의역설
- 메탈퍼즐
- 건담
- 유루건
- 게임
Archives
- Today
- Total
.Zzumbong
[leetCode/JS] 3477. Fruits Into Baskets II 본문
난이도 [ 😊 ] Easy
문제 설명
You are given two arrays of integers, fruits and baskets, each of length n,
where fruits[i] represents the quantity of the ith type of fruit, and baskets[j] represents the capacity of the jth basket. From left to right, place the fruits according to these rules:
Each fruit type must be placed in the leftmost available basket with
- a capacity greater than or equal to the quantity of that fruit type. Each basket can hold only one type of fruit.
If a fruit type cannot be placed in any basket, it remains unplaced.
Return the number of fruit types that remain unplaced after all possible allocations are made.
|
입출력 예
Example 1:
Input: fruits = [4,2,5], baskets = [3,5,4] Output: 1
Explanation:
fruits[0] = 4 is placed in baskets[1] = 5.
fruits[1] = 2 is placed in baskets[0] = 3.
fruits[2] = 5 cannot be placed in baskets[2] = 4.
Since one fruit type remains unplaced, we return 1.
|
Example 2:
Input: fruits = [3,6,1], baskets = [6,4,7] Output: 0
Explanation:
fruits[0] = 3 is placed in baskets[0] = 6.
fruits[1] = 6 cannot be placed in baskets[1] = 4 (insufficient capacity) but can be placed in the next available basket, baskets[2] = 7. fruits[2] = 1 is placed in baskets[1] = 4.
Since all fruits are successfully placed, we return 0.
|
Constraints
n == fruits.length == baskets.length
1 <= n <= 100
1 <= fruits[i], baskets[i] <= 1000
|
내 솔루션
/**
* @param {number[]} fruits
* @param {number[]} baskets
* @return {number}
*/
var numOfUnplacedFruits = function (fruits, baskets) {
const n = fruits.length;
let used = 0;
for (let i = 0; i < fruits.length; i++) {
for (let j = 0; j < baskets.length; j++) {
if (fruits[i] <= baskets[j]) {
baskets[j] -= baskets[j];
used++;
break;
}
}
}
return n - used;
};
감상평
- 문제 독해가 어려워서 헤맴ㅋㅋㅋ
'coding test > leetCode' 카테고리의 다른 글
[leetCode/JS]1408. String Matching in an Array (1) | 2025.01.07 |
---|---|
[leetCode/JS] 343. Integer Break (0) | 2023.10.06 |
[leetCode/JS] 706. Design HashMap (0) | 2023.10.04 |
[leetCode/JS] 6. Zigzag Conversion (0) | 2023.10.04 |
[leetCode/JS] 1512. Number of Good Pairs (0) | 2023.10.03 |
Comments