diff --git a/linked-list-cycle/Seoya0512.py b/linked-list-cycle/Seoya0512.py new file mode 100644 index 0000000000..3cad5460c2 --- /dev/null +++ b/linked-list-cycle/Seoya0512.py @@ -0,0 +1,9 @@ +class Solution: + def hasCycle(self, head: Optional[ListNode]) -> bool: + cycle_set = set() + while head: + if head in cycle_set: + return True + cycle_set.add(head) + head = head.next + return False diff --git a/maximum-product-subarray/Seoya0512.py b/maximum-product-subarray/Seoya0512.py new file mode 100644 index 0000000000..c26f4ea59e --- /dev/null +++ b/maximum-product-subarray/Seoya0512.py @@ -0,0 +1,19 @@ +''' +이전 곱을 저장해서 곱셈 연산을 줄이는 방식 +해당 연산 방식은 Time Limited Exceeded 오류를 발생했습니다. + +시간 복잡도: O(n^2) +- 외부 for-loop과 내부 for-loop이 각각 n번씩 실행되기 때문 +공간 복잡도: O(1) +''' +class Solution: + def maxProduct(self, nums: List[int]) -> int: + max_product = nums[0] + + for i in range(len(nums)): + prev = 1 + for j in range(i, len(nums)): + prev = prev * nums[j] + max_product = max(max_product, prev) + + return max_product