Skip to content

Commit 26589b6

Browse files
refactor 466
1 parent d93d92c commit 26589b6

File tree

1 file changed

+24
-20
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+24
-20
lines changed

src/main/java/com/fishercoder/solutions/_466.java

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,33 @@
2222
*/
2323
public class _466 {
2424

25-
/**credit: https://discuss.leetcode.com/topic/70707/ugly-java-brute-force-solution-but-accepted-1088ms*/
26-
public int getMaxRepetitions(String s1, int n1, String s2, int n2) {
27-
char[] s1chars = s1.toCharArray();
28-
char[] s2chars = s2.toCharArray();
29-
int i = 0;
30-
int j = 0;
31-
int count1 = 0;
32-
int count2 = 0;
33-
while (count1 < n1) {
34-
if (s1chars[i] == s2chars[j]) {
35-
j++;
36-
if (j == s2.length()) {
37-
j = 0;
38-
count2++;
25+
public static class Solution1 {
26+
/**
27+
* credit: https://discuss.leetcode.com/topic/70707/ugly-java-brute-force-solution-but-accepted-1088ms
28+
*/
29+
public int getMaxRepetitions(String s1, int n1, String s2, int n2) {
30+
char[] s1chars = s1.toCharArray();
31+
char[] s2chars = s2.toCharArray();
32+
int i = 0;
33+
int j = 0;
34+
int count1 = 0;
35+
int count2 = 0;
36+
while (count1 < n1) {
37+
if (s1chars[i] == s2chars[j]) {
38+
j++;
39+
if (j == s2.length()) {
40+
j = 0;
41+
count2++;
42+
}
43+
}
44+
i++;
45+
if (i == s1.length()) {
46+
i = 0;
47+
count1++;
3948
}
4049
}
41-
i++;
42-
if (i == s1.length()) {
43-
i = 0;
44-
count1++;
45-
}
50+
return count2 / n2;
4651
}
47-
return count2 / n2;
4852
}
4953

5054
}

0 commit comments

Comments
 (0)