1, arrays, linked lists, stacks, queues

1, the array

Construction is simple, simple index O (1)

Takes a continuous space, check for the presence or absence of an element (n) time complexity O

some problems:

https://leetcode-cn.com/problems/valid-anagram/

2, the list

Flexibility in the allocation of space, add or delete time complexity O (1), suitable for the indefinite number of data deletion algorithm approach Add

Query element O (n)

some problems:

https://leetcode-cn.com/problems/reverse-nodes-in-k-group/ ( K flip list in groups )

3. Stack

LIFO (the LIFO), all operations are completed stack can be used to achieve a single linked list (the list head operation)

Applicable to the case concerned only the last operation

some problems:

(Effective parentheses) https://leetcode-cn.com/problems/valid-parentheses/

(Daily temperature) https://leetcode-cn.com/problems/daily-temperatures/

4, queue

First In First Out (FIFO), the tail joined team head deletion, can be used to achieve double-linked list

Adapted to process the data in a certain order, and changing data.

BFS

Deque

Suitable for a dynamic change in length of the window

some problems:

239. The sliding window maximum

Guess you like

Origin www.cnblogs.com/feihu-h/p/12154418.html