Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions longest-repeating-character-replacement/jylee2033.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sliding Window
  • 설명: 이 코드는 고정된 크기의 윈도우를 이동시키며 조건에 맞게 확장하거나 축소하는 슬라이딩 윈도우 패턴을 사용하여 최장 부분 문자열을 찾는다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
class Solution:
def characterReplacement(self, s: str, k: int) -> int:
# "AABABBA", 1
# l = 0
# r = 4
# max_freq = 0
# max_len = 4
# {"A":1, "B":2}

l = 0
max_len = 0
max_freq = 0
seen = {}

for r, char in enumerate(s):
seen[char] = seen.get(char, 0) + 1
max_freq = max(max_freq, seen[char])

while (r - l + 1) - max_freq > k:
seen[s[l]] -= 1
l += 1

max_len = max(max_len, r - l + 1)
return max_len

# Time Complexity: O(n)
# Space Complexity: O(1)
14 changes: 14 additions & 0 deletions reverse-bits/jylee2033.py
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Bit Manipulation
  • 설명: 이 코드는 비트 연산자를 활용하여 정수의 비트 순서를 뒤집는 방식으로, 비트 조작을 통해 문제를 해결하는 Bit Manipulation 패턴에 속합니다.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution:
def reverseBits(self, n: int) -> int:
# 0100

res = 0

for _ in range(32):
res = (res << 1) | (n & 1)
n >>= 1
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 문제 bit 연산으로 풀이하셨군요! 덕분에 추가로 알아갑니다 :)


return res

# Time Complexity: O(1)
# Space Complexity: O(1)
Loading