diff --git a/solution/1700-1799/1701.Average Waiting Time/README.md b/solution/1700-1799/1701.Average Waiting Time/README.md index dc589cf6d6791..2f9b35e9ec2e6 100644 --- a/solution/1700-1799/1701.Average Waiting Time/README.md +++ b/solution/1700-1799/1701.Average Waiting Time/README.md @@ -161,6 +161,19 @@ function averageWaitingTime(customers: number[][]): number { } ``` +#### JavaScript + +```js +function averageWaitingTime(customers) { + let [tot, t] = [0, 0]; + for (const [a, b] of customers) { + t = Math.max(t, a) + b; + tot += t - a; + } + return tot / customers.length; +} +``` + diff --git a/solution/1700-1799/1701.Average Waiting Time/README_EN.md b/solution/1700-1799/1701.Average Waiting Time/README_EN.md index 12bca99037400..32b4e2e0c8c5c 100644 --- a/solution/1700-1799/1701.Average Waiting Time/README_EN.md +++ b/solution/1700-1799/1701.Average Waiting Time/README_EN.md @@ -159,6 +159,19 @@ function averageWaitingTime(customers: number[][]): number { } ``` +#### JavaScript + +```js +function averageWaitingTime(customers) { + let [tot, t] = [0, 0]; + for (const [a, b] of customers) { + t = Math.max(t, a) + b; + tot += t - a; + } + return tot / customers.length; +} +``` + diff --git a/solution/1700-1799/1701.Average Waiting Time/Solution.js b/solution/1700-1799/1701.Average Waiting Time/Solution.js new file mode 100644 index 0000000000000..09ae234089c0c --- /dev/null +++ b/solution/1700-1799/1701.Average Waiting Time/Solution.js @@ -0,0 +1,8 @@ +function averageWaitingTime(customers) { + let [tot, t] = [0, 0]; + for (const [a, b] of customers) { + t = Math.max(t, a) + b; + tot += t - a; + } + return tot / customers.length; +}