From 155a4c9c2e4c0fd24db63751914c4eba55b30e36 Mon Sep 17 00:00:00 2001 From: Manohar Reddy Poreddy Date: Mon, 15 Jan 2024 15:49:35 +0530 Subject: [PATCH 1/2] Update README.md --- .../README.md | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md index f49ba055f0c59..9129485027576 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md @@ -172,6 +172,31 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { ``` +### **JavaScript** + +```js +var latestTimeCatchTheBus = function (buses, passengers, capacity) { + buses.sort((a, b) => a - b); + passengers.sort((a, b) => a - b); + let j = 0, + c; + for (const t of buses) { + c = capacity; + while (c && j < passengers.length && passengers[j] <= t) { + --c; + ++j; + } + } + --j; + let ans = c > 0 ? buses[buses.length - 1] : passengers[j]; + while (j >= 0 && passengers[j] === ans) { + --ans; + --j; + } + return ans; +}; +``` + ### **...** ``` From 31d79f1f1005b90cb8f919e570d202c795eba7e5 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Mon, 15 Jan 2024 19:48:48 +0800 Subject: [PATCH 2/2] Update README.md --- .../2300-2399/2332.The Latest Time to Catch a Bus/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md index 9129485027576..e6d40dc993123 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README.md @@ -175,6 +175,12 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { ### **JavaScript** ```js +/** + * @param {number[]} buses + * @param {number[]} passengers + * @param {number} capacity + * @return {number} + */ var latestTimeCatchTheBus = function (buses, passengers, capacity) { buses.sort((a, b) => a - b); passengers.sort((a, b) => a - b);