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
36 changes: 36 additions & 0 deletions 3sum/hellojoyworldz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# 문제: https://leetcode.com/problems/3sum/
# 해설: https://www.algodale.com/problems/3sum/
# 위치: https://github.com/DaleStudy/leetcode-study/tree/main/3sum

from typing import List


class Solution:
def threeSum(self, nums: List[int]) -> List[List[int]]:
nums.sort()
result = []

for i in range(len(nums)):
if i > 0 and nums[i] == nums[i - 1]:
continue
Comment on lines +13 to +15

@parkhojeong parkhojeong Jul 4, 2026

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.

정렬되어 있는 상태라 nums[i] > 0 인 부분은 break해도 좋을 거 같습니다!
ex. [-1, 0, 1, 2, 3, 4, 5, 6, 7], i = 2 부터는 양수 + 양수 + 양수

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

아 그러네요, 제가 놓쳤습니다
세심한 피드백 정말 감사합니다! 🙇‍♂️


left, right = i + 1, len(nums) - 1
while left < right:
total = nums[i] + nums[left] + nums[right]

if total < 0:
left += 1
elif total > 0:
right -= 1
else:
result.append([nums[i], nums[left], nums[right]])
left += 1
right -= 1

while left < right and nums[left] == nums[left - 1]:
left += 1
while left < right and nums[right] == nums[right + 1]:
right -= 1

return result

11 changes: 11 additions & 0 deletions climbing-stairs/hellojoyworldz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# 문제: https://leetcode.com/problems/climbing-stairs/
# 해설: https://www.algodale.com/problems/climbing-stairs/
# 위치: https://github.com/DaleStudy/leetcode-study/tree/main/climbing-stairs

class Solution:
def climbStairs(self, n: int) -> int:
prev2, prev1 = 1, 1
for _ in range(n - 1):
prev2, prev1 = prev1, prev2 + prev1
return prev1

@parkhojeong parkhojeong Jul 4, 2026

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.

개인적으로는 이런 부분들이 읽으면서 생각을 한 번 더 하게 되었던 거 같습니다!

  • prev2, prev1에 1, 1 이 할당된 것도 문제의 조건과 어떻게 연결되는건지
  • n = 1, n = 2 일때 어떻게 처리되는지
  • prev1이 리턴하는게 n 값 까지 계산한 후 prev1 을 리턴하는 것인지

가독성을 고려한다면 배열을 사용해봐도 괜찮을 거 같습니다~

class Solution:
    def climbStairs(self, n: int) -> int:
        if n == 1:
            return 1

        arr = [0] * n
        arr[0], arr[1] = 1, 2

        for i in range(2, n):
            arr[i] = arr[i - 1] + arr[i - 2]

        return arr[-1]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

안 그래도 가독성 부분이 고민이였는데,
제안해 주신 것처럼 배열을 쓰니까 흐름이 훨씬 직관적이고 좋네요!


24 changes: 24 additions & 0 deletions product-of-array-except-self/hellojoyworldz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# 문제: https://leetcode.com/problems/product-of-array-except-self/
# 해설: https://www.algodale.com/problems/product-of-array-except-self/
# 위치: https://github.com/DaleStudy/leetcode-study/tree/main/product-of-array-except-self

from typing import List


class Solution:
def productExceptSelf(self, nums: List[int]) -> List[int]:
n = len(nums)
answer = [1] * n

left = 1
for i in range(n):
answer[i] = left
left *= nums[i]

right = 1
for i in reversed(range(n)):
answer[i] *= right
right *= nums[i]
Comment on lines +19 to +21

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.

reversed(range(n)) 사용하신거 간결하고 좋네요~


return answer

8 changes: 8 additions & 0 deletions valid-anagram/hellojoyworldz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# 문제: https://leetcode.com/problems/valid-anagram/
# 해설: https://www.algodale.com/problems/valid-anagram/
# 위치: https://github.com/DaleStudy/leetcode-study/tree/main/valid-anagram

class Solution:
def isAnagram(self, s: str, t: str) -> bool:
return sorted(s) == sorted(t)

Comment on lines +5 to +8

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.

간결하고 좋네요!

26 changes: 26 additions & 0 deletions validate-binary-search-tree/hellojoyworldz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 문제: https://leetcode.com/problems/validate-binary-search-tree/
# 해설: https://www.algodale.com/problems/validate-binary-search-tree/
# 위치: https://github.com/DaleStudy/leetcode-study/tree/main/validate-binary-search-tree

from typing import Optional

# Definition for a binary tree node.
class TreeNode:
def __init__(self, val=0, left=None, right=None):
self.val = val
self.left = left
self.right = right

class Solution:
def isValidBST(self, root: Optional[TreeNode]) -> bool:
def check(node: Optional[TreeNode], low: float, high: float) -> bool:
if not node:
return True

if not (low < node.val < high):
return False
Comment on lines +20 to +21

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.

(log < node.val < high) 사용하신거 좋네요!


return check(node.left, low, node.val) and check(node.right, node.val, high)

return check(root, float("-inf"), float("inf"))

Loading