Skip to content

Commit 23fd800

Browse files
committed
feat: 2주차 풀이 완료
1 parent dbacbc9 commit 23fd800

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

invert-binary-tree/saysimple.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Definition for a binary tree node.
2+
# class TreeNode:
3+
# def __init__(self, val=0, left=None, right=None):
4+
# self.val = val
5+
# self.left = left
6+
# self.right = right
7+
# TC, SC: O(n), O(n)
8+
class Solution:
9+
def invertTree(self, root: Optional[TreeNode]) -> Optional[TreeNode]:
10+
if not root:
11+
return None
12+
13+
left = root.left
14+
root.left = root.right
15+
root.right = left
16+
17+
self.invertTree(root.left)
18+
self.invertTree(root.right)
19+
20+
return root

linked-list-cycle/saysimple.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Definition for singly-linked list.
2+
# class ListNode:
3+
# def __init__(self, x):
4+
# self.val = x
5+
# self.next = None
6+
# TC, SC: O(n), O(1)
7+
class Solution:
8+
def hasCycle(self, head: Optional[ListNode]) -> bool:
9+
if not head:
10+
return None
11+
12+
head.pos = 0
13+
14+
while head.next:
15+
if hasattr(head.next, "pos"):
16+
return True
17+
head.next.pos = head.pos + 1
18+
head = head.next
19+
20+
return False

merge-two-sorted-lists/saysimple.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# def __init__(self, val=0, next=None):
44
# self.val = val
55
# self.next = next
6+
# TC, SC: O(n), O(n)
67
class Solution:
78
def mergeTwoLists(self, list1: Optional[ListNode], list2: Optional[ListNode]) -> Optional[ListNode]:
89
if not (list1 and list2):

valid-parentheses/saysimple.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# TC, SC: O(n), O(n)
12
class Solution:
23
def isValid(self, s: str) -> bool:
34
arr = []

0 commit comments

Comments
 (0)