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
18 changes: 18 additions & 0 deletions combination-sum/hestia-park.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution:
def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]:
result = []
def dfs(result,remain, path, start):
if remain==0:
result.append(path[:])
return
if remain < 0:
return
for i in range(start, len(candidates)):
path.append(candidates[i])
dfs(result,remain - candidates[i], path, i)
path.pop()

dfs(result,target, [], 0)
return result


12 changes: 12 additions & 0 deletions maximum-subarray/hestia-park.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class Solution:
def maxSubArray(self, nums: List[int]) -> int:
dp = 0
max_ = float('-inf')
for i in range(len(nums)):
dp += nums[i]
max_ = max(max_, dp)
if dp < 0:
dp = 0 # 누적합이 0보다 작아지면 버리고 새로 시작
return max_


20 changes: 20 additions & 0 deletions number-of-1-bits/hestia-park.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution:
def hammingWeight(self, n: int) -> int:
# ans=0
# # bit=[]
# moc=n
# while moc > 0:
# nam=moc%2
# if nam==1:
# ans+=1
# moc=int((moc-nam)/2)

# return ans
# using Brian Kernighan’s Algorithm
count = 0
while n:
n &= n - 1
count += 1
return count


20 changes: 20 additions & 0 deletions valid-palindrome/hestia-park.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Solution:
def isPalindrome(self, s: str) -> bool:
# lower_text = s.lower()
# clean_text = re.sub(r'[^a-z0-9]', '', lower_text)
# if len(clean_text) ==0:
# return True

# j = len(clean_text) - 1
# ans = True

# for i in range(len(clean_text) // 2):
# if clean_text[i] != clean_text[j]:
# ans = False
# break
# j -= 1
# return ans
n = "".join(c for c in s if c.isalnum()).lower()
return n == n[::-1]