Skip to content

Commit 56ce555

Browse files
authored
feat: 8 weeks (#1904)
1 parent 18ed4fa commit 56ce555

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
class Solution:
2+
def characterReplacement(self, s: str, k: int) -> int:
3+
start, max_len, max_freq = 0, 0, 0
4+
5+
window = {}
6+
for end in range(len(s)):
7+
char = s[end]
8+
window[char] = window.get(char, 0) + 1
9+
max_freq = max(max_freq, window[char])
10+
11+
while (end - start + 1) - max_freq > k:
12+
left_char = s[start]
13+
window[left_char] -= 1
14+
start += 1
15+
16+
max_len = end - start + 1 if end - start + 1 > max_len else max_len
17+
18+
return max_len
19+
20+
21+
if __name__ == "__main__":
22+
s = Solution()
23+
print(s.characterReplacement('ABAB', 2))

reverse-bits/chordpli.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution:
2+
def reverseBits(self, n: int) -> int:
3+
return int(format(n, "032b")[::-1], 2)
4+
5+
def reverse_bits(self, n: int):
6+
result = 0
7+
for i in range(32):
8+
lsb = n & 1
9+
result <<= 1
10+
result |= lsb
11+
n >>= 1
12+
return result
13+
14+
15+
if __name__ == "__main__":
16+
s = Solution()
17+
print(s.reverse_bits(10))

0 commit comments

Comments
 (0)