We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 55e3857 commit 5e9dc13Copy full SHA for 5e9dc13
βrepeated-string-match.js
@@ -0,0 +1,25 @@
1
+/**
2
+ * @param {string} A
3
+ * @param {string} B
4
+ * @return {number}
5
+ */
6
+const repeatedStringMatch = (A, B) => {
7
+ const lenA = A.length;
8
+ const lenB = B.length;
9
+
10
+ for (let i = 0; i < lenA; i++) {
11
+ let j = 0;
12
13
+ while (j < lenB && B[j] === A[(i + j) % lenA]) {
14
+ j++;
15
+ }
16
17
+ if (j === lenB) {
18
+ return Math.ceil((i + j) / lenA);
19
20
21
22
+ return -1;
23
+};
24
25
+export { repeatedStringMatch };
0 commit comments