Skip to content

Commit 1470cf9

Browse files
committed
feat: add solutions to lc problem: No.1598
No.1598.Crawler Log Folder
1 parent d3bc03c commit 1470cf9

File tree

5 files changed

+144
-0
lines changed

5 files changed

+144
-0
lines changed

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,59 @@ func minOperations(logs []string) int {
144144
}
145145
```
146146

147+
### **C**
148+
149+
```c
150+
#define max(a,b) (((a) > (b)) ? (a) : (b))
151+
152+
int minOperations(char **logs, int logsSize) {
153+
int depth = 0;
154+
for (int i = 0; i < logsSize; i++) {
155+
char *log = logs[i];
156+
if (!strcmp(log, "../")) {
157+
depth = max(0, depth - 1);
158+
} else if (strcmp(log, "./")) {
159+
depth++;
160+
}
161+
}
162+
return depth;
163+
}
164+
```
165+
166+
### **TypeScript**
167+
168+
```ts
169+
function minOperations(logs: string[]): number {
170+
let depth = 0;
171+
for (const log of logs) {
172+
if (log === '../') {
173+
depth = Math.max(0, depth - 1);
174+
} else if (log !== './') {
175+
depth++;
176+
}
177+
}
178+
return depth;
179+
}
180+
```
181+
182+
### **Rust**
183+
184+
```rust
185+
impl Solution {
186+
pub fn min_operations(logs: Vec<String>) -> i32 {
187+
let mut depth = 0;
188+
for log in logs.iter() {
189+
if log == "../" {
190+
depth = 0.max(depth - 1);
191+
} else if log != "./" {
192+
depth += 1;
193+
}
194+
}
195+
depth
196+
}
197+
}
198+
```
199+
147200
### **...**
148201

149202
```

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,59 @@ func minOperations(logs []string) int {
131131
}
132132
```
133133

134+
### **C**
135+
136+
```c
137+
#define max(a,b) (((a) > (b)) ? (a) : (b))
138+
139+
int minOperations(char **logs, int logsSize) {
140+
int depth = 0;
141+
for (int i = 0; i < logsSize; i++) {
142+
char *log = logs[i];
143+
if (!strcmp(log, "../")) {
144+
depth = max(0, depth - 1);
145+
} else if (strcmp(log, "./")) {
146+
depth++;
147+
}
148+
}
149+
return depth;
150+
}
151+
```
152+
153+
### **TypeScript**
154+
155+
```ts
156+
function minOperations(logs: string[]): number {
157+
let depth = 0;
158+
for (const log of logs) {
159+
if (log === '../') {
160+
depth = Math.max(0, depth - 1);
161+
} else if (log !== './') {
162+
depth++;
163+
}
164+
}
165+
return depth;
166+
}
167+
```
168+
169+
### **Rust**
170+
171+
```rust
172+
impl Solution {
173+
pub fn min_operations(logs: Vec<String>) -> i32 {
174+
let mut depth = 0;
175+
for log in logs.iter() {
176+
if log == "../" {
177+
depth = 0.max(depth - 1);
178+
} else if log != "./" {
179+
depth += 1;
180+
}
181+
}
182+
depth
183+
}
184+
}
185+
```
186+
134187
### **...**
135188

136189
```
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#define max(a,b) (((a) > (b)) ? (a) : (b))
2+
3+
int minOperations(char **logs, int logsSize) {
4+
int depth = 0;
5+
for (int i = 0; i < logsSize; i++) {
6+
char *log = logs[i];
7+
if (!strcmp(log, "../")) {
8+
depth = max(0, depth - 1);
9+
} else if (strcmp(log, "./")) {
10+
depth++;
11+
}
12+
}
13+
return depth;
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
impl Solution {
2+
pub fn min_operations(logs: Vec<String>) -> i32 {
3+
let mut depth = 0;
4+
for log in logs.iter() {
5+
if log == "../" {
6+
depth = 0.max(depth - 1);
7+
} else if log != "./" {
8+
depth += 1;
9+
}
10+
}
11+
depth
12+
}
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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++;
8+
}
9+
}
10+
return depth;
11+
}

0 commit comments

Comments
 (0)