Skip to content

Commit 37291ee

Browse files
authored
Merge pull request #2262 from Seoya0512/main
[Seoya0512] WEEK 09 Solutions
2 parents 0556fe3 + 9effdd5 commit 37291ee

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

linked-list-cycle/Seoya0512.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Solution:
2+
def hasCycle(self, head: Optional[ListNode]) -> bool:
3+
cycle_set = set()
4+
while head:
5+
if head in cycle_set:
6+
return True
7+
cycle_set.add(head)
8+
head = head.next
9+
return False
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'''
2+
이전 곱을 저장해서 곱셈 연산을 줄이는 방식
3+
해당 연산 방식은 Time Limited Exceeded 오류를 발생했습니다.
4+
5+
시간 복잡도: O(n^2)
6+
- 외부 for-loop과 내부 for-loop이 각각 n번씩 실행되기 때문
7+
공간 복잡도: O(1)
8+
'''
9+
class Solution:
10+
def maxProduct(self, nums: List[int]) -> int:
11+
max_product = nums[0]
12+
13+
for i in range(len(nums)):
14+
prev = 1
15+
for j in range(i, len(nums)):
16+
prev = prev * nums[j]
17+
max_product = max(max_product, prev)
18+
19+
return max_product

0 commit comments

Comments
 (0)