From 4070d48be172960c52809fec76332e6a072553af Mon Sep 17 00:00:00 2001 From: Manohar Reddy Poreddy Date: Mon, 15 Jan 2024 11:58:01 +0530 Subject: [PATCH 01/12] Add JS solution Adding a js solution that works, formatted with eslint & prettier, with 2 spaces --- .../README_EN.md | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index 48e9342da1108..173e0558f3b3e 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -157,13 +157,32 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { ### **TypeScript** ```ts - -``` - -### **...** - ``` +### **JavaScript** + +```js +var latestTimeCatchTheBus = function (buses, passengers, capacity) { + buses.sort((a, b) => a - b) + passengers.sort((a, b) => a - b) + let j = 0 + let c + for (const t of buses) { + c = capacity + while (c && j < passengers.length && passengers[j] <= t) { + c-- + j++ + } + } + j-- + let latestArrTime = passengers[j] + if (c) latestArrTime = buses[buses.length - 1] + while (j >= 0 && passengers[j] === latestArrTime) { + latestArrTime-- + j-- + } + return latestArrTime +} ``` From 8e0394463c208148625090d295670b8091219d80 Mon Sep 17 00:00:00 2001 From: manoharreddyporeddy Date: Mon, 15 Jan 2024 06:28:54 +0000 Subject: [PATCH 02/12] style: format code and docs with prettier --- .../README_EN.md | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index 173e0558f3b3e..d49d3d034e2dc 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -157,32 +157,33 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { ### **TypeScript** ```ts + ``` ### **JavaScript** ```js var latestTimeCatchTheBus = function (buses, passengers, capacity) { - buses.sort((a, b) => a - b) - passengers.sort((a, b) => a - b) - let j = 0 - let c - for (const t of buses) { - c = capacity - while (c && j < passengers.length && passengers[j] <= t) { - c-- - j++ + buses.sort((a, b) => a - b); + passengers.sort((a, b) => a - b); + let j = 0; + let c; + for (const t of buses) { + c = capacity; + while (c && j < passengers.length && passengers[j] <= t) { + c--; + j++; + } } - } - j-- - let latestArrTime = passengers[j] - if (c) latestArrTime = buses[buses.length - 1] - while (j >= 0 && passengers[j] === latestArrTime) { - latestArrTime-- - j-- - } - return latestArrTime -} + j--; + let latestArrTime = passengers[j]; + if (c) latestArrTime = buses[buses.length - 1]; + while (j >= 0 && passengers[j] === latestArrTime) { + latestArrTime--; + j--; + } + return latestArrTime; +}; ``` From 051c473189a689bff1fb1fbab665eda26259e7da Mon Sep 17 00:00:00 2001 From: Manohar Reddy Poreddy Date: Mon, 15 Jan 2024 12:03:21 +0530 Subject: [PATCH 03/12] Update README_EN.md --- .../2332.The Latest Time to Catch a Bus/README_EN.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index d49d3d034e2dc..a8db5bcc5b414 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -186,4 +186,8 @@ var latestTimeCatchTheBus = function (buses, passengers, capacity) { }; ``` +### **...** + +``` + From b0e38a0852a99c04fea520a0b7c38da76a720f7b Mon Sep 17 00:00:00 2001 From: manoharreddyporeddy Date: Mon, 15 Jan 2024 06:34:04 +0000 Subject: [PATCH 04/12] style: format code and docs with prettier --- .../2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md | 1 + 1 file changed, 1 insertion(+) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index a8db5bcc5b414..a5ddba20f3bca 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -191,3 +191,4 @@ var latestTimeCatchTheBus = function (buses, passengers, capacity) { ``` +``` From 57f7abfd040586f3c911e52920c6ce1a4d5d2f29 Mon Sep 17 00:00:00 2001 From: Manohar Reddy Poreddy Date: Mon, 15 Jan 2024 12:13:32 +0530 Subject: [PATCH 05/12] Update README_EN.md --- .../2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index a5ddba20f3bca..e63d762dfb841 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -190,5 +190,6 @@ var latestTimeCatchTheBus = function (buses, passengers, capacity) { ``` - ``` + + From 07373d162e51352525c457bef70bfbe57ad42398 Mon Sep 17 00:00:00 2001 From: Manohar Reddy Poreddy Date: Mon, 15 Jan 2024 15:26:20 +0530 Subject: [PATCH 06/12] Update solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md Co-authored-by: thinkasany <480968828@qq.com> --- .../2332.The Latest Time to Catch a Bus/README_EN.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index e63d762dfb841..997c705dc04d0 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -183,7 +183,12 @@ var latestTimeCatchTheBus = function (buses, passengers, capacity) { j--; } return latestArrTime; -}; + let ans = c > 0 ? buses[buses.length - 1] : passengers[j]; + while (j >= 0 && ans === passengers[j]) { + --ans; + --j; + } + return ans; ``` ### **...** From e0f85f1771d8c0bc61269b79dc7e206f99d11ba2 Mon Sep 17 00:00:00 2001 From: Manohar Reddy Poreddy Date: Mon, 15 Jan 2024 15:26:27 +0530 Subject: [PATCH 07/12] Update solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md Co-authored-by: thinkasany <480968828@qq.com> --- .../2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index 997c705dc04d0..2be526470425d 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -167,7 +167,7 @@ var latestTimeCatchTheBus = function (buses, passengers, capacity) { buses.sort((a, b) => a - b); passengers.sort((a, b) => a - b); let j = 0; - let c; + let j = 0, c; for (const t of buses) { c = capacity; while (c && j < passengers.length && passengers[j] <= t) { From 3a7fa5f18395cfe5d857e77f806f420b21dab1ce Mon Sep 17 00:00:00 2001 From: Manohar Reddy Poreddy Date: Mon, 15 Jan 2024 15:38:55 +0530 Subject: [PATCH 08/12] Update README_EN.md --- .../README_EN.md | 41 ++++++++----------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index 2be526470425d..3261bf434d4f3 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -164,31 +164,24 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { ```js var latestTimeCatchTheBus = function (buses, passengers, capacity) { - buses.sort((a, b) => a - b); - passengers.sort((a, b) => a - b); - let j = 0; - let j = 0, c; - for (const t of buses) { - c = capacity; - while (c && j < passengers.length && passengers[j] <= t) { - c--; - j++; - } - } - j--; - let latestArrTime = passengers[j]; - if (c) latestArrTime = buses[buses.length - 1]; - while (j >= 0 && passengers[j] === latestArrTime) { - latestArrTime--; - j--; + 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; } - return latestArrTime; - let ans = c > 0 ? buses[buses.length - 1] : passengers[j]; - while (j >= 0 && ans === passengers[j]) { - --ans; - --j; - } - return ans; + } + --j; + let ans = c > 0 ? buses[buses.length - 1] : passengers[j]; + while (j >= 0 && passengers[j] === ans) { + --ans; + --j; + } + return ans; +}; ``` ### **...** From 639ca55899b6d95e6a8974b8fa1d604f2587fb4b Mon Sep 17 00:00:00 2001 From: manoharreddyporeddy Date: Mon, 15 Jan 2024 10:09:50 +0000 Subject: [PATCH 09/12] style: format code and docs with prettier --- .../README_EN.md | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index 3261bf434d4f3..5a806d9d940a5 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -164,23 +164,24 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { ```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; + 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; + let ans = c > 0 ? buses[buses.length - 1] : passengers[j]; + while (j >= 0 && passengers[j] === ans) { + --ans; + --j; + } + return ans; }; ``` From 2a0c8287f8590ddc186b08de55f28db076d80cad Mon Sep 17 00:00:00 2001 From: Manohar Reddy Poreddy Date: Mon, 15 Jan 2024 15:43:44 +0530 Subject: [PATCH 10/12] Update README_EN.md --- .../2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index 5a806d9d940a5..be8786b0eebe8 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -166,8 +166,7 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { var latestTimeCatchTheBus = function (buses, passengers, capacity) { buses.sort((a, b) => a - b); passengers.sort((a, b) => a - b); - let j = 0, - c; + let j = 0, c; for (const t of buses) { c = capacity; while (c && j < passengers.length && passengers[j] <= t) { From 8df54ada7fee747f57724e7236e63821b4247e1c Mon Sep 17 00:00:00 2001 From: manoharreddyporeddy Date: Mon, 15 Jan 2024 10:14:34 +0000 Subject: [PATCH 11/12] style: format code and docs with prettier --- .../2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index be8786b0eebe8..5a806d9d940a5 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -166,7 +166,8 @@ func latestTimeCatchTheBus(buses []int, passengers []int, capacity int) int { var latestTimeCatchTheBus = function (buses, passengers, capacity) { buses.sort((a, b) => a - b); passengers.sort((a, b) => a - b); - let j = 0, c; + let j = 0, + c; for (const t of buses) { c = capacity; while (c && j < passengers.length && passengers[j] <= t) { From 44167d98f207ffd9f0f89a13a68adb2fda910fc8 Mon Sep 17 00:00:00 2001 From: Libin YANG Date: Mon, 15 Jan 2024 19:48:25 +0800 Subject: [PATCH 12/12] Update README_EN.md --- .../2332.The Latest Time to Catch a Bus/README_EN.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md index 5a806d9d940a5..a205dc82a732d 100644 --- a/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md +++ b/solution/2300-2399/2332.The Latest Time to Catch a Bus/README_EN.md @@ -163,6 +163,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);