Skip to content

Commit 24d3bfc

Browse files
authored
feat: add ts solution to lc problem: No.1433 (doocs#1458)
1 parent d70fc1f commit 24d3bfc

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

solution/1400-1499/1433.Check If a String Can Break Another String/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,26 @@ func checkIfCanBreak(s1 string, s2 string) bool {
136136
}
137137
```
138138

139+
### **TypeScript**
140+
141+
```ts
142+
function checkIfCanBreak(s1: string, s2: string): boolean {
143+
const cs1: string[] = Array.from(s1);
144+
const cs2: string[] = Array.from(s2);
145+
cs1.sort();
146+
cs2.sort();
147+
const check = (cs1: string[], cs2: string[]) => {
148+
for (let i = 0; i < cs1.length; i++) {
149+
if (cs1[i] < cs2[i]) {
150+
return false;
151+
}
152+
}
153+
return true;
154+
};
155+
return check(cs1, cs2) || check(cs2, cs1);
156+
}
157+
```
158+
139159
### **...**
140160

141161
```

solution/1400-1499/1433.Check If a String Can Break Another String/README_EN.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,26 @@ func checkIfCanBreak(s1 string, s2 string) bool {
123123
}
124124
```
125125

126+
### **TypeScript**
127+
128+
```ts
129+
function checkIfCanBreak(s1: string, s2: string): boolean {
130+
const cs1: string[] = Array.from(s1);
131+
const cs2: string[] = Array.from(s2);
132+
cs1.sort();
133+
cs2.sort();
134+
const check = (cs1: string[], cs2: string[]) => {
135+
for (let i = 0; i < cs1.length; i++) {
136+
if (cs1[i] < cs2[i]) {
137+
return false;
138+
}
139+
}
140+
return true;
141+
};
142+
return check(cs1, cs2) || check(cs2, cs1);
143+
}
144+
```
145+
126146
### **...**
127147

128148
```
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
function checkIfCanBreak(s1: string, s2: string): boolean {
2+
const cs1: string[] = Array.from(s1);
3+
const cs2: string[] = Array.from(s2);
4+
cs1.sort();
5+
cs2.sort();
6+
const check = (cs1: string[], cs2: string[]) => {
7+
for (let i = 0; i < cs1.length; i++) {
8+
if (cs1[i] < cs2[i]) {
9+
return false;
10+
}
11+
}
12+
return true;
13+
};
14+
return check(cs1, cs2) || check(cs2, cs1);
15+
}

0 commit comments

Comments
 (0)