λ¬Έμ
νμ΄ κ³Όμ
λ¬Έμ λΆλ₯λ νμ μκ³ λ¦¬μ¦
μ΄μ§λ§ μ
λ ₯ κ°μ λ²μκ° ν¬μ§ μκΈ° λλ¬Έμ λΈλ£¨νΈ ν¬μ€
λ‘λ μΆ©λΆν ν΄κ²°ν μ μλ λ¬Έμ μμ΅λλ€.
μ°λ¦¬κ° μ°ΎμμΌ νλ κ²μ ν μμ μ νμν μ΅λ capacity μ
λλ€.
λ°λΌμ μκ°μ 0.5 λ¨μλ‘ μ¦κ°μν€λ©° κ²ΉμΉλ μ΅λ ꡬκ°μ μ°Ύλλ‘ ν©λλ€.
μ΄λ 0.5μ© μ¦κ°μμΌμ€ μ΄μ λ κ±°λ¦¬κ° 1 λ¨μμ΄κΈ° λλ¬Έμ
λλ€.
(μ μ κ°μ λ°©λ²μΌλ‘ ꡬνν λΆμ μ½λλ₯Ό 보λ μμ μ§μ μ ν¬ν¨νκ³ μ’
λ£ μκ°μ μ μΈνμ¬
1μ© μ¦κ°μμΌλ λλλ‘ κ΅¬νν λ°©λ²μ΄ μμλλ° κ·Έκ² λ κ°λ¨ν΄λ³΄μ
λλ€.)
μ½λ
/**
* @param {number[][]} trips
* @param {number} capacity
* @return {boolean}
*/
var carPooling = function (trips, capacity) {
let maxValue = 0;
for (let time = 0.0; time <= 1000; time += 0.5) {
let need = 0;
for (let [c, s, e] of trips) {
if (s < time && time < e) {
need += c;
}
}
maxValue = Math.max(maxValue, need);
}
return maxValue <= capacity;
};
const trips = [
[3, 2, 7],
[3, 7, 9],
[8, 3, 9],
];
const capacity = 11;
console.log(carPooling(trips, capacity));
λ°μν
'π algorithm > leetcode' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
LeetCode 283 - Move Zeroes (Medium) (0) | 2021.03.02 |
---|---|
LeetCode 678 - Valid Parenthesis String (Medium) (0) | 2021.03.02 |
LeetCode 49 - Group Anagrams (Medium) (0) | 2021.03.02 |
LeetCode 200 - Number of Islands (Medium) (0) | 2021.03.02 |
LeetCode 64 - Minimum Path Sum (Medium) (0) | 2021.03.02 |
π¬ λκΈ