算法与数据结构
linked-list-cycle-2
linked-list-cycle
Method 1: class Solution(object): def hasCycle(self, head): slow = fast = head while fast and fast.next: fast = fast.next.next slow = slow.next ...
Swap-nodes-in-pairs
def swapInPairs(self, head): pre, pre.next = self, head while pre.next and pre.next.next: a = pre.next b = a.next pre.next, b.next, a.next = b, a, b.next ...
Reverse Linked List
Method 1: class Solution: def reverseList(self, head: ListNode) -> ListNode: pre = None cur = head while cur: nexttmp = cur.next cur.next =...
Array and Linked list
Array: search element is quickly Time complexity o(1) add element and delete element is slow. Time complexity o(n) Linked list: search element is slow. Time complexity o(n) add element and...