problem
solution
two pointer ,slow fast pointers 用於linked list檢查是否包含環
option 1
1 | class Solution { |
option 2 - Two pointers
1 | class Solution { |
analysis
- option 1
- time complexity
O(n)
- space complexity
O(n)
- time complexity
- option 2
- time complexity
O(n)
- space complexity
O(1)
- time complexity