FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Mod: minors · OmarShawky1/Problem-Solving-Map@d06a63d · GitHub

Commit d06a63d

Browse files
committed
Mod: minors
1 parent 00f6a8a commit d06a63d

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎arrays/slidingWindow/CharacterReplacement.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,7 @@ public int characterReplacement(String s, int k) {
3131

3232
public static void test() {
3333
CharacterReplacement c = new CharacterReplacement();
34+
assert c.characterReplacement("ABAB", 2) == 4;
35+
assert c.characterReplacement("AABABBA", 1) == 4;
3436
}
3537
}

‎arrays/slidingWindow/CheckInclusion.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public boolean checkInclusion1(String s1, String s2) {
3232
return false;
3333
}
3434

35+
// Most maintainable
3536
public boolean checkInclusion2(String s1, String s2) {
3637
if (s1.length() > s2.length()) return false;
3738

@@ -71,7 +72,7 @@ public boolean checkInclusion(String s1, String s2) {
7172

7273
for (char c : s1.toCharArray()) ++count[c - 'a'];
7374

74-
for (int right = 0; right < n2; ++right) {
75+
for (int right = 0; right < n2; right++) {
7576
// If char count is 1 or more, decrement remaining window size k
7677
if (count[s2Arr[right] - 'a']-- > 0) k--;
7778

@@ -80,7 +81,7 @@ public boolean checkInclusion(String s1, String s2) {
8081
// And all our window size is correct (right is not so far ahead of left more than k), return true
8182
if (right - left + 1 == n1) return true;
8283

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.
8485
if (++count[s2Arr[left++] - 'a'] > 0) k++;
8586
}
8687
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL