Skip to content

Commit a75a405

Browse files
refactor 395
1 parent 1d77b03 commit a75a405

File tree

1 file changed

+4
-0
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public int longestSubstring(String s, int k) {
3535
}
3636

3737
int findLongestSubstring(char[] chars, int start, int end, int k) {
38+
/**Base case 1 of 2*/
3839
if (end - start < k) {
3940
return 0;
4041
}
@@ -44,6 +45,7 @@ int findLongestSubstring(char[] chars, int start, int end, int k) {
4445
count[index]++;
4546
}
4647

48+
/**For every character in the above frequency table*/
4749
for (int i = 0; i < 26; i++) {
4850
if (count[i] < k && count[i] > 0) {
4951
for (int j = start; j < end; j++) {
@@ -55,6 +57,8 @@ int findLongestSubstring(char[] chars, int start, int end, int k) {
5557
}
5658
}
5759
}
60+
/**Base case 2 of 2:
61+
* when any characters in this substring has repeated at least k times, then this entire substring is a valid answer*/
5862
return end - start;
5963
}
6064
}

0 commit comments

Comments
 (0)