Skip to content

Commit 4109feb

Browse files
authored
feat: add ts solution to lc problem: No.0686 (#1500)
1 parent d32778c commit 4109feb

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

solution/0600-0699/0686.Repeated String Match/README.md

+21
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ func repeatedStringMatch(a string, b string) int {
133133
}
134134
```
135135

136+
### **TypeScript**
137+
138+
```ts
139+
function repeatedStringMatch(a: string, b: string): number {
140+
const m: number = a.length,
141+
n: number = b.length;
142+
let ans: number = Math.ceil(n / m);
143+
let t: string = a.repeat(ans);
144+
145+
for (let i = 0; i < 3; i++) {
146+
if (t.includes(b)) {
147+
return ans;
148+
}
149+
ans++;
150+
t += a;
151+
}
152+
153+
return -1;
154+
}
155+
```
156+
136157
### **...**
137158

138159
```

solution/0600-0699/0686.Repeated String Match/README_EN.md

+21
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,27 @@ func repeatedStringMatch(a string, b string) int {
110110
}
111111
```
112112

113+
### **TypeScript**
114+
115+
```ts
116+
function repeatedStringMatch(a: string, b: string): number {
117+
const m: number = a.length,
118+
n: number = b.length;
119+
let ans: number = Math.ceil(n / m);
120+
let t: string = a.repeat(ans);
121+
122+
for (let i = 0; i < 3; i++) {
123+
if (t.includes(b)) {
124+
return ans;
125+
}
126+
ans++;
127+
t += a;
128+
}
129+
130+
return -1;
131+
}
132+
```
133+
113134
### **...**
114135

115136
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
function repeatedStringMatch(a: string, b: string): number {
2+
const m: number = a.length,
3+
n: number = b.length;
4+
let ans: number = Math.ceil(n / m);
5+
let t: string = a.repeat(ans);
6+
7+
for (let i = 0; i < 3; i++) {
8+
if (t.includes(b)) {
9+
return ans;
10+
}
11+
ans++;
12+
t += a;
13+
}
14+
15+
return -1;
16+
}

0 commit comments

Comments
 (0)