Skip to content

Commit 10e9abd

Browse files
authored
Merge pull request #2114 from devyulbae/main
[devyulbae] WEEK 03 solutions
2 parents abb6eb5 + 72b9c90 commit 10e9abd

File tree

5 files changed

+88
-0
lines changed

5 files changed

+88
-0
lines changed

β€Ždecode-ways/devyulbae.pyβ€Ž

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
class Solution:
2+
def numDecodings(self, s: str) -> int:
3+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""
2+
Blind75 - length of longest substring without repeating characters
3+
https://leetcode.com/problems/longest-substring-without-repeating-characters/
4+
μ‹œκ°„λ³΅μž‘λ„ : O(n)
5+
κ³΅κ°„λ³΅μž‘λ„ : O(min(m, n)) (문자 μ§‘ν•© char_index_map의 크기, μ΅œλŒ€λŠ” n = len(s))
6+
풀이 : μŠ¬λΌμ΄λ”© μœˆλ„μš° 기법을 μ‚¬μš©ν•œ λ¬Έμžμ—΄ 순회
7+
"""
8+
9+
10+
class Solution:
11+
def lengthOfLongestSubstring(self, s: str) -> int:
12+
max_count = 0
13+
start = 0
14+
char_index_map = {}
15+
16+
for i, char in enumerate(s):
17+
if char in char_index_map and char_index_map[char] >= start:
18+
start = char_index_map[char] + 1
19+
char_index_map[char] = i
20+
else:
21+
char_index_map[char] = i
22+
max_count = max(max_count, i - start + 1)
23+
24+
return max_count
25+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
Blind75 - 5. Maximum Subarray
3+
LeetCode Problem Link: https://leetcode.com/problems/maximum-subarray/
4+
5+
ν†΅κ³ΌλŠ” ν–ˆλŠ”λ° μ‹œκ°„λ³΅μž‘λ„ O(n^2)λΌμ„œ μ’€ 아쉽닀...νˆ¬ν¬μΈν„°λ‘œ ν’€ μˆ˜λ„ μžˆμ„ κ±° 같은데...
6+
"""
7+
from typing import List
8+
9+
class Solution:
10+
def maxSubArray(self, nums: List[int]) -> int:
11+
max_total = nums[0]
12+
13+
for s in range(len(nums)):
14+
total = 0
15+
for e in range(s, len(nums)):
16+
total += nums[e]
17+
if total > max_total:
18+
max_total = total
19+
return max_total
20+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"""
2+
Blind75 - Number of 1 Bits
3+
https://leetcode.com/problems/number-of-1-bits/
4+
μ‹œκ°„λ³΅μž‘λ„ : O(log n)
5+
κ³΅κ°„λ³΅μž‘λ„ : O(1)
6+
7+
풀이 :
8+
파이썬의 λ‚΄μž₯ν•¨μˆ˜ bin() -> O(log n)
9+
λ¬Έμžμ—΄ λ©”μ„œλ“œ count() -> O(log n)
10+
11+
"""
12+
13+
class Solution:
14+
def hammingWeight(self, n: int) -> int:
15+
return str(bin(n)).count('1')
16+
17+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""
2+
Blind75 - Valid Palindrome
3+
https://leetcode.com/problems/valid-palindrome/
4+
5+
μ‹œκ°„λ³΅μž‘λ„ O(n), κ³΅κ°„λ³΅μž‘λ„ O(n)
6+
7+
isalnum() ν•¨μˆ˜λŠ” μ‹œκ°„λ³΅μž‘λ„ O(1)μ΄λ―€λ‘œ ν•„ν„°λ§ν•˜λŠ” 과정도 O(n)이닀.
8+
[::-1] μŠ¬λΌμ΄μ‹±λ„ O(n)이닀.
9+
λ”°λΌμ„œ 전체 μ‹œκ°„λ³΅μž‘λ„λŠ” O(n)이닀.
10+
11+
12+
Runtime Beats
13+
7ms 82.67%
14+
15+
Memory Beats
16+
23.14 MB 17.23%
17+
"""
18+
19+
class Solution:
20+
def isPalindrome(self, s: str) -> bool:
21+
filtered_s = ''.join(char.lower() for char in s if char.isalnum())
22+
return filtered_s == filtered_s[::-1]
23+

0 commit comments

Comments
Β (0)