Skip to content

Commit 6beb6bd

Browse files
authored
feat: add js solution to lc problem: No.1598 (doocs#3245)
1 parent 062bfc0 commit 6beb6bd

File tree

4 files changed

+64
-21
lines changed

4 files changed

+64
-21
lines changed

solution/1500-1599/1598.Crawler Log Folder/README.md

+23-7
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,31 @@ func minOperations(logs []string) int {
160160

161161
```ts
162162
function minOperations(logs: string[]): number {
163-
let depth = 0;
164-
for (const log of logs) {
165-
if (log === '../') {
166-
depth = Math.max(0, depth - 1);
167-
} else if (log !== './') {
168-
depth++;
163+
let ans = 0;
164+
for (const x of logs) {
165+
if (x === '../') {
166+
ans && ans--;
167+
} else if (x !== './') {
168+
ans++;
169169
}
170170
}
171-
return depth;
171+
return ans;
172+
}
173+
```
174+
175+
#### JavaScript
176+
177+
```ts
178+
function minOperations(logs) {
179+
let ans = 0;
180+
for (const x of logs) {
181+
if (x === '../') {
182+
ans && ans--;
183+
} else if (x !== './') {
184+
ans++;
185+
}
186+
}
187+
return ans;
172188
}
173189
```
174190

solution/1500-1599/1598.Crawler Log Folder/README_EN.md

+23-7
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,31 @@ func minOperations(logs []string) int {
157157

158158
```ts
159159
function minOperations(logs: string[]): number {
160-
let depth = 0;
161-
for (const log of logs) {
162-
if (log === '../') {
163-
depth = Math.max(0, depth - 1);
164-
} else if (log !== './') {
165-
depth++;
160+
let ans = 0;
161+
for (const x of logs) {
162+
if (x === '../') {
163+
ans && ans--;
164+
} else if (x !== './') {
165+
ans++;
166166
}
167167
}
168-
return depth;
168+
return ans;
169+
}
170+
```
171+
172+
#### JavaScript
173+
174+
```js
175+
function minOperations(logs) {
176+
let ans = 0;
177+
for (const x of logs) {
178+
if (x === '../') {
179+
ans && ans--;
180+
} else if (x !== './') {
181+
ans++;
182+
}
183+
}
184+
return ans;
169185
}
170186
```
171187

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function minOperations(logs) {
2+
let ans = 0;
3+
for (const x of logs) {
4+
if (x === '../') {
5+
ans && ans--;
6+
} else if (x !== './') {
7+
ans++;
8+
}
9+
}
10+
return ans;
11+
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function minOperations(logs: string[]): number {
2-
let depth = 0;
3-
for (const log of logs) {
4-
if (log === '../') {
5-
depth = Math.max(0, depth - 1);
6-
} else if (log !== './') {
7-
depth++;
2+
let ans = 0;
3+
for (const x of logs) {
4+
if (x === '../') {
5+
ans && ans--;
6+
} else if (x !== './') {
7+
ans++;
88
}
99
}
10-
return depth;
10+
return ans;
1111
}

0 commit comments

Comments
 (0)