Skip to content

Commit f1b4978

Browse files
committed
日积月累了Python有序集合SortedList
from sortedcontainers import SortedList
1 parent dc5ec37 commit f1b4978

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

Solutions/Other-Accumulation-SomeTips.md

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ for i in chain(a, b):
114114

115115
### Python bisect
116116

117-
二分查找用
117+
python二分查找用
118118

119119
```bisect.bisect_right(list, val)```类似于C++的```upper_bound(list.begin(), lise.end(), val) - list.begin()```
120120

@@ -204,7 +204,7 @@ The 1-th is Second
204204
The 2-th is Third
205205
```
206206

207-
### Python 双端队列 deque
207+
### Python双端队列 deque
208208

209209
```python
210210
from collections import deque
@@ -215,7 +215,7 @@ dq.pop()
215215
dq.popleft()
216216
```
217217

218-
### Python 优先队列 heapq
218+
### Python优先队列 heapq
219219

220220
Python优先队列小元素先出队(小根堆)。
221221

@@ -228,6 +228,24 @@ heapq.heappush(pq, 3)
228228
heapq.heappop(pq) # 1
229229
```
230230

231+
### Python有序集合SortedList
232+
233+
类似于```C++``````multiset```
234+
235+
```python
236+
from sortedcontainers import SortedList
237+
238+
se = SortedList()
239+
se.add(2) # SortedList([2])
240+
se.add(1) # SortedList([1, 2])
241+
se.add(3) # SortedList([1, 2, 3])
242+
se.add(2) # SortedList([1, 2, 2, 3])
243+
se.discard(2) # SortedList([1, 2, 3])
244+
se[0] # 1
245+
se[-1] # 3
246+
2 in se # True
247+
```
248+
231249
## About Website
232250

233251
### ip扫描工具censys

0 commit comments

Comments
 (0)