

- class Solution(object):
- def hasCycle(self, head):
- """
- :type head: ListNode
- :rtype: bool
- """
- if head is None:
- return False
- slow = head
- fast = head
- while(fast is not None and fast.next is not None):
- slow = slow.next
- fast = fast.next.next
- if slow == fast:
- return True
- return False

- class Solution(object):
- def numRescueBoats(self, people, limit):
- """
- :type people: List[int]
- :type limit: int
- :rtype: int
- """
- if len(people) == 0:
- return 0
- people.sort()
- i = 0
- j = len(people) - 1
- res = 0
- while(i <= j):
- if people[i] + people[j] <= limit:
- i += 1
- j -= 1
- res += 1
- return res