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 162c1fc commit 62ef8fbCopy full SHA for 62ef8fb
1062-longest-repeating-substring.js
@@ -1,3 +1,35 @@
1
+/**
2
+ * @param {string} s
3
+ * @return {number}
4
+ */
5
+const longestRepeatingSubstring = function(s) {
6
+ let left = 0;
7
+ let right = s.length - 1;
8
+ while(left < right) {
9
+ let pivot = Math.floor((left + right + 1) / 2);
10
+ if (hasRepeat(s, pivot)) {
11
+ left = pivot;
12
+ } else {
13
+ right = pivot - 1;
14
+ }
15
16
+ return left;
17
+};
18
+
19
+const hasRepeat = (s, l) => {
20
+ const strings = new Set();
21
+ for (let i = 0; i < s.length - l + 1; i++) {
22
+ const sub = s.substr(i, l);
23
+ if (strings.has(sub)) {
24
+ return true;
25
26
+ strings.add(sub);
27
28
+ return false;
29
+}
30
31
+// another
32
33
/**
34
* @param {string} s
35
* @return {number}
0 commit comments