Skip to content

Commit 968b9b8

Browse files
authored
Update Python刷题技巧笔记.md
1 parent 04af16b commit 968b9b8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

docs/Leetcode_Solutions/Python/Summary/Python刷题技巧笔记.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,22 @@ Operations on deque :
191191
```
192192
[Deque in Python](https://www.geeksforgeeks.org/deque-in-python/)
193193

194+
195+
```python
196+
# 16. getRandom: Returns a random element from current set of elements. Each element must have the same probability of being returned.
197+
198+
# 这种是常规方法
199+
idx = random.randint(0, self.length-1)
200+
return self.lst[idx]
201+
# 神奇函数
202+
return random.choice(self.lst)
203+
```
204+
205+
206+
207+
208+
209+
194210
```
195211
达尔大佬对刷leetcode和刷笔试题有几个建议:
196212

0 commit comments

Comments
 (0)