From 3565ed809b1b0c992d56d75b6a8890cb0551880a Mon Sep 17 00:00:00 2001 From: rain84 Date: Wed, 10 Jul 2024 03:40:50 +0300 Subject: [PATCH 1/2] feat: update ts solution to lc problem: No.1598 --- .../1500-1599/1598.Crawler Log Folder/README.md | 14 +++++++------- .../1500-1599/1598.Crawler Log Folder/README_EN.md | 14 +++++++------- .../1500-1599/1598.Crawler Log Folder/Solution.ts | 14 +++++++------- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/solution/1500-1599/1598.Crawler Log Folder/README.md b/solution/1500-1599/1598.Crawler Log Folder/README.md index a15b7d479895a..b4cfd2b34b8fc 100644 --- a/solution/1500-1599/1598.Crawler Log Folder/README.md +++ b/solution/1500-1599/1598.Crawler Log Folder/README.md @@ -160,15 +160,15 @@ func minOperations(logs []string) int { ```ts function minOperations(logs: string[]): number { - let depth = 0; - for (const log of logs) { - if (log === '../') { - depth = Math.max(0, depth - 1); - } else if (log !== './') { - depth++; + let ans = 0; + for (const x of logs) { + if (x === '../') { + ans && ans--; + } else if (x !== './') { + ans++; } } - return depth; + return ans; } ``` diff --git a/solution/1500-1599/1598.Crawler Log Folder/README_EN.md b/solution/1500-1599/1598.Crawler Log Folder/README_EN.md index f28ffe2898b97..26db2256e1286 100644 --- a/solution/1500-1599/1598.Crawler Log Folder/README_EN.md +++ b/solution/1500-1599/1598.Crawler Log Folder/README_EN.md @@ -157,15 +157,15 @@ func minOperations(logs []string) int { ```ts function minOperations(logs: string[]): number { - let depth = 0; - for (const log of logs) { - if (log === '../') { - depth = Math.max(0, depth - 1); - } else if (log !== './') { - depth++; + let ans = 0; + for (const x of logs) { + if (x === '../') { + ans && ans--; + } else if (x !== './') { + ans++; } } - return depth; + return ans; } ``` diff --git a/solution/1500-1599/1598.Crawler Log Folder/Solution.ts b/solution/1500-1599/1598.Crawler Log Folder/Solution.ts index 9a45622f944c2..cb1295231c4fd 100644 --- a/solution/1500-1599/1598.Crawler Log Folder/Solution.ts +++ b/solution/1500-1599/1598.Crawler Log Folder/Solution.ts @@ -1,11 +1,11 @@ function minOperations(logs: string[]): number { - let depth = 0; - for (const log of logs) { - if (log === '../') { - depth = Math.max(0, depth - 1); - } else if (log !== './') { - depth++; + let ans = 0; + for (const x of logs) { + if (x === '../') { + ans && ans--; + } else if (x !== './') { + ans++; } } - return depth; + return ans; } From b5ec4d57455c7a4b2bdc984ddc5dbaf0cfe0d2fb Mon Sep 17 00:00:00 2001 From: rain84 Date: Wed, 10 Jul 2024 03:42:46 +0300 Subject: [PATCH 2/2] feat: add js solution to lc problem: No.1598 --- .../1500-1599/1598.Crawler Log Folder/README.md | 16 ++++++++++++++++ .../1598.Crawler Log Folder/README_EN.md | 16 ++++++++++++++++ .../1598.Crawler Log Folder/Solution.js | 11 +++++++++++ 3 files changed, 43 insertions(+) create mode 100644 solution/1500-1599/1598.Crawler Log Folder/Solution.js diff --git a/solution/1500-1599/1598.Crawler Log Folder/README.md b/solution/1500-1599/1598.Crawler Log Folder/README.md index b4cfd2b34b8fc..021e2b08152f6 100644 --- a/solution/1500-1599/1598.Crawler Log Folder/README.md +++ b/solution/1500-1599/1598.Crawler Log Folder/README.md @@ -172,6 +172,22 @@ function minOperations(logs: string[]): number { } ``` +#### JavaScript + +```ts +function minOperations(logs) { + let ans = 0; + for (const x of logs) { + if (x === '../') { + ans && ans--; + } else if (x !== './') { + ans++; + } + } + return ans; +} +``` + #### Rust ```rust diff --git a/solution/1500-1599/1598.Crawler Log Folder/README_EN.md b/solution/1500-1599/1598.Crawler Log Folder/README_EN.md index 26db2256e1286..f7f00684bf7ff 100644 --- a/solution/1500-1599/1598.Crawler Log Folder/README_EN.md +++ b/solution/1500-1599/1598.Crawler Log Folder/README_EN.md @@ -169,6 +169,22 @@ function minOperations(logs: string[]): number { } ``` +#### JavaScript + +```js +function minOperations(logs) { + let ans = 0; + for (const x of logs) { + if (x === '../') { + ans && ans--; + } else if (x !== './') { + ans++; + } + } + return ans; +} +``` + #### Rust ```rust diff --git a/solution/1500-1599/1598.Crawler Log Folder/Solution.js b/solution/1500-1599/1598.Crawler Log Folder/Solution.js new file mode 100644 index 0000000000000..ea8cad5a66594 --- /dev/null +++ b/solution/1500-1599/1598.Crawler Log Folder/Solution.js @@ -0,0 +1,11 @@ +function minOperations(logs) { + let ans = 0; + for (const x of logs) { + if (x === '../') { + ans && ans--; + } else if (x !== './') { + ans++; + } + } + return ans; +}