File tree 4 files changed +64
-21
lines changed
solution/1500-1599/1598.Crawler Log Folder
4 files changed +64
-21
lines changed Original file line number Diff line number Diff line change @@ -160,15 +160,31 @@ func minOperations(logs []string) int {
160
160
161
161
``` ts
162
162
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 ++ ;
169
169
}
170
170
}
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 ;
172
188
}
173
189
```
174
190
Original file line number Diff line number Diff line change @@ -157,15 +157,31 @@ func minOperations(logs []string) int {
157
157
158
158
``` ts
159
159
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 ++ ;
166
166
}
167
167
}
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;
169
185
}
170
186
```
171
187
Original file line number Diff line number Diff line change
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 number Diff line number Diff line change 1
1
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 ++ ;
8
8
}
9
9
}
10
- return depth ;
10
+ return ans ;
11
11
}
You can’t perform that action at this time.
0 commit comments