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
3 changes: 3 additions & 0 deletions decode-ways/devyulbae.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Solution:
def numDecodings(self, s: str) -> int:

25 changes: 25 additions & 0 deletions longest-substring-without-repeating-characters/devyulbae.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""
Blind75 - length of longest substring without repeating characters
https://leetcode.com/problems/longest-substring-without-repeating-characters/
시간복잡도 : O(n)
공간복잡도 : O(min(m, n)) (문자 집합 char_index_map의 크기, 최대는 n = len(s))
풀이 : 슬라이딩 윈도우 기법을 사용한 문자열 순회
"""


class Solution:
def lengthOfLongestSubstring(self, s: str) -> int:
max_count = 0
start = 0
char_index_map = {}

for i, char in enumerate(s):
if char in char_index_map and char_index_map[char] >= start:
start = char_index_map[char] + 1
char_index_map[char] = i
else:
char_index_map[char] = i
max_count = max(max_count, i - start + 1)

return max_count

20 changes: 20 additions & 0 deletions maximum-subarray/devyulbae.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Blind75 - 5. Maximum Subarray
LeetCode Problem Link: https://leetcode.com/problems/maximum-subarray/

통과는 했는데 시간복잡도 O(n^2)라서 좀 아쉽다...투포인터로 풀 수도 있을 거 같은데...
"""
from typing import List

class Solution:
def maxSubArray(self, nums: List[int]) -> int:
max_total = nums[0]

for s in range(len(nums)):
total = 0
for e in range(s, len(nums)):
total += nums[e]
if total > max_total:
max_total = total
return max_total

17 changes: 17 additions & 0 deletions number-of-1-bits/devyulbae.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""
Blind75 - Number of 1 Bits
https://leetcode.com/problems/number-of-1-bits/
시간복잡도 : O(log n)
공간복잡도 : O(1)

풀이 :
파이썬의 내장함수 bin() -> O(log n)
문자열 메서드 count() -> O(log n)

"""

class Solution:
def hammingWeight(self, n: int) -> int:
return str(bin(n)).count('1')


23 changes: 23 additions & 0 deletions valid-palindrome/devyulbae.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Blind75 - Valid Palindrome
https://leetcode.com/problems/valid-palindrome/

시간복잡도 O(n), 공간복잡도 O(n)

isalnum() 함수는 시간복잡도 O(1)이므로 필터링하는 과정도 O(n)이다.
[::-1] 슬라이싱도 O(n)이다.
따라서 전체 시간복잡도는 O(n)이다.


Runtime Beats
7ms 82.67%

Memory Beats
23.14 MB 17.23%
"""

class Solution:
def isPalindrome(self, s: str) -> bool:
filtered_s = ''.join(char.lower() for char in s if char.isalnum())
return filtered_s == filtered_s[::-1]

Copy link
Contributor

Choose a reason for hiding this comment

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

현재 구현은 문자열을 여러 차례 순회하며 중간 결과를 생성하기 때문에 전체 처리 비용이 커집니다.

  1. 알파벳, 숫자만 추출해 새로운 문자열 생성
  2. 역순 문자열 생성(추가 메모리 사용)
  3. 두 문자열 비교

투포인터 방식을 적용하면 문자 검사, 정규화, 앞뒤 비교를 하나의 루프에서 처리할 수 있어 순회 비용을 단일 O(N)으로 줄일 수 있습니다. 별도 메모리를 사용하지 않으며, 불일치 시 즉시 종료할 수 있어 전체 런타임 측면에서도 더 효율적입니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 감사합니다! 한번 최적화해볼게요ㅎㅎ