forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_1062.java
More file actions
25 lines (23 loc) · 717 Bytes
/
_1062.java
File metadata and controls
25 lines (23 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package com.fishercoder.solutions;
import java.util.HashSet;
import java.util.Set;
public class _1062 {
public static class Solution1 {
/**
* My completely original, although brute-force solution, on 1/20/2022.
*/
public int longestRepeatingSubstring(String s) {
Set<String> seen = new HashSet<>();
for (int j = s.length() - 1; j > 0; j--) {
int len = j;
for (int i = 0; i <= s.length() - j; i++) {
if (!seen.add(s.substring(i, i + len))) {
return len;
}
}
seen.clear();
}
return 0;
}
}
}