| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -31,5 +31,7 @@ public int characterReplacement(String s, int k) { | |||
| 31 | 31 | ||
| 32 | 32 | public static void test() { | |
| 33 | 33 | CharacterReplacement c = new CharacterReplacement(); | |
| 34 | + assert c.characterReplacement("ABAB", 2) == 4; | ||
| 35 | + assert c.characterReplacement("AABABBA", 1) == 4; | ||
| 34 | 36 | } | |
| 35 | 37 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,6 +32,7 @@ public boolean checkInclusion1(String s1, String s2) { | |||
| 32 | 32 | return false; | |
| 33 | 33 | } | |
| 34 | 34 | ||
| 35 | + // Most maintainable | ||
| 35 | 36 | public boolean checkInclusion2(String s1, String s2) { | |
| 36 | 37 | if (s1.length() > s2.length()) return false; | |
| 37 | 38 | ||
@@ -71,7 +72,7 @@ public boolean checkInclusion(String s1, String s2) { | |||
| 71 | 72 | ||
| 72 | 73 | for (char c : s1.toCharArray()) ++count[c - 'a']; | |
| 73 | 74 | ||
| 74 | - for (int right = 0; right < n2; ++right) { | ||
| 75 | + for (int right = 0; right < n2; right++) { | ||
| 75 | 76 | // If char count is 1 or more, decrement remaining window size k | |
| 76 | 77 | if (count[s2Arr[right] - 'a']-- > 0) k--; | |
| 77 | 78 | ||
@@ -80,7 +81,7 @@ public boolean checkInclusion(String s1, String s2) { | |||
| 80 | 81 | // And all our window size is correct (right is not so far ahead of left more than k), return true | |
| 81 | 82 | if (right - left + 1 == n1) return true; | |
| 82 | 83 | ||
| 83 | - // else, if value is -1 make it 0 and if it is 0 or more, increase window size | ||
| 84 | + // else, if value is -1 make it 0 and loop. if it is 0 or more, increase window size and break. | ||
| 84 | 85 | if (++count[s2Arr[left++] - 'a'] > 0) k++; | |
| 85 | 86 | } | |
| 86 | 87 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments