Monday, December 12, 2016

LinkedList的套路

1.two pointer
两个pointer
1.slow,slow = slow.next正常loop
2.fast , fast = fast.next.next 每次走快一步

Ex:
查cycle

2.partition
Ex:
用merge sort来sort list

3.用stack存倒序读数
Ex:
 https://leetcode.com/problems/add-two-numbers-ii/


4.Recursive 解法
 Ex:
http://rainykat.blogspot.com/2016/12/leetcode-remove-duplates-in-linkedlist.html

No comments:

Post a Comment