Skip to content

Commit e2184f3

Browse files
committed
week 3 sol
1 parent 01f1f0d commit e2184f3

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

combination-sum/hestia-park.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
3+
result = []
4+
def dfs(result,remain, path, start):
5+
if remain==0:
6+
result.append(path[:])
7+
return
8+
if remain < 0:
9+
return
10+
for i in range(start, len(candidates)):
11+
path.append(candidates[i])
12+
dfs(result,remain - candidates[i], path, i)
13+
path.pop()
14+
15+
dfs(result,target, [], 0)
16+
return result
17+
18+

maximum-subarray/hestia-park.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution:
2+
def maxSubArray(self, nums: List[int]) -> int:
3+
dp = 0
4+
max_ = float('-inf')
5+
for i in range(len(nums)):
6+
dp += nums[i]
7+
max_ = max(max_, dp)
8+
if dp < 0:
9+
dp = 0 # 누적합이 0보다 작아지면 버리고 새로 시작
10+
return max_
11+
12+

number-of-1-bits/hestia-park.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def hammingWeight(self, n: int) -> int:
3+
# ans=0
4+
# # bit=[]
5+
# moc=n
6+
# while moc > 0:
7+
# nam=moc%2
8+
# if nam==1:
9+
# ans+=1
10+
# moc=int((moc-nam)/2)
11+
12+
# return ans
13+
# using Brian Kernighan’s Algorithm
14+
count = 0
15+
while n:
16+
n &= n - 1
17+
count += 1
18+
return count
19+
20+

valid-palindrome/hestia-park.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
# lower_text = s.lower()
4+
# clean_text = re.sub(r'[^a-z0-9]', '', lower_text)
5+
# if len(clean_text) ==0:
6+
# return True
7+
8+
# j = len(clean_text) - 1
9+
# ans = True
10+
11+
# for i in range(len(clean_text) // 2):
12+
# if clean_text[i] != clean_text[j]:
13+
# ans = False
14+
# break
15+
# j -= 1
16+
# return ans
17+
n = "".join(c for c in s if c.isalnum()).lower()
18+
return n == n[::-1]
19+
20+

0 commit comments

Comments
 (0)