Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions find-minimum-in-rotated-sorted-array/Chaedie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Solution:
1) 순회하며 이전 값이 현재 값보다 크거나 같다면 현재 값이 최소값이다.
2) 끝까지 돌아도 최소값이 없을 경우 첫번쨰 값이 최소값이다.
Time: O(n)
Copy link
Contributor

Choose a reason for hiding this comment

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

문제 조건에 이런게 있습니다 😔

You must write an algorithm that runs in O(log n) time.

이 문제의 난이도가 medium인 이유..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

헛... 해당 조건을 놓쳤네요 감사합니다.. 이게 medium이라고? 하면서 풀었네요.. 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

binary search 풀이도 추가했습니다..!

Space: O(1)
"""


class Solution:
def findMin(self, nums: List[int]) -> int:
for i in range(1, len(nums)):
if nums[i - 1] >= nums[i]:
return nums[i]

return nums[0]
24 changes: 24 additions & 0 deletions linked-list-cycle/Chaedie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Solution:
1) 사이클이 있다면 무한 루프가 발생할것이다.
2) 사이클이 없다면 언젠가 null 이 될것이다.
3) 따라서 두개의 포인터를 사용하여 동일한 Node에 도달하는 지 확인한다.
4) null 이 된다면 사이클이 없다는 뜻이다.
Time: O(n)
Space: O(1)
"""


class Solution:
def hasCycle(self, head: Optional[ListNode]) -> bool:
if not head or not head.next:
return False

slow = head
fast = head.next
while slow and fast and fast.next:
slow = slow.next
fast = fast.next.next
if slow == fast:
return True
return False