【leetcode 1】LinkList and Queue and Stack

一、LinkList

1.1 how to find the middle node of a linked list

1.2 用快慢指针判定一个linklist是否有环

1.3 Insert a node in a sorted linked list(simple)

Becareful about two corner cases: head and tail

1.4 How to merge two sorted linked list into one long sorted list

why or when should we use a dummy node?
When we want to append new elements to an initially empty linkedList.
we do not have an initial head node. in this case, we can new a dummy node to act as a head node.

1.5

N1->N2->N3 ->…->Nn
(N1->Nn)->(N2->Nn-1) - >…
Solution:
Step1: Find the middle node of the LinkedList
Step2: reverse the 2nd half
Step3: Merge two linkedList into one long linkedList

1.6 Partition List

Give a linked list and a target value x, partition it such that all nodes less than x are listed before the nodes larger than or equal to target value x. (keep the original relative order of the nodes in each of the two partitions.)

For example:
Input: 1->6->3->2>5 x = 4
Output: 1->3->2->6->5

Solution:

你可能感兴趣的:(笔试面试相关,leetcode)