Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit91888f7

Browse files
update 1062
1 parent36553b0 commit91888f7

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

‎src/main/java/com/fishercoder/solutions/secondthousand/_1062.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@
66
publicclass_1062 {
77
publicstaticclassSolution1 {
88
/**
9-
* My completely original, although brute-force solution, on 1/20/2022.
9+
* My completely original solution, although kind of brute-force, on 1/20/2022.
10+
* Two pointer technique:
11+
* j starts from the right, i starts from the left,
12+
* as soon as we are able to find a repeated substring, we return.
1013
*/
1114
publicintlongestRepeatingSubstring(Strings) {
1215
Set<String>seen =newHashSet<>();
1316
for (intj =s.length() -1;j >0;j--) {
14-
intlen =j;
15-
for (inti =0;i <=s.length() -j;i++) {
16-
if (!seen.add(s.substring(i,i +len))) {
17-
returnlen;
17+
for (inti =0;i +j <=s.length();i++) {
18+
if (!seen.add(s.substring(i,i +j))) {
19+
returnj;
1820
}
1921
}
2022
seen.clear();

‎src/test/java/com/fishercoder/secondthousand/_1062Test.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
packagecom.fishercoder.secondthousand;
22

33
importcom.fishercoder.solutions.secondthousand._1062;
4-
importorg.junit.BeforeClass;
5-
importorg.junit.Test;
4+
importorg.junit.jupiter.api.BeforeEach;
5+
importorg.junit.jupiter.api.Test;
66

7-
importstaticorg.junit.Assert.assertEquals;
7+
importstaticorg.junit.jupiter.api.Assertions.assertEquals;
88

99
publicclass_1062Test {
1010
privatestatic_1062.Solution1solution1;
1111

12-
@BeforeClass
13-
publicstaticvoidsetup() {
12+
@BeforeEach
13+
publicvoidsetup() {
1414
solution1 =new_1062.Solution1();
1515
}
1616

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp