일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- Python
- Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- 30. Substring with Concatenation of All Words
- 43. Multiply Strings
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- Protocol
- iterator
- shiba
- Regular Expression
- 파이썬
- kaggle
- Class
- data science
- 715. Range Module
- t1
- LeetCode
- 운영체제
- 밴픽
- attribute
- Decorator
- 시바견
- 프로그래머스
- DWG
- concurrency
- Generator
- 컴퓨터의 구조
- Python Code
Archives
- Today
- Total
Scribbling
LeetCode: 384. Shuffle an Array 본문
Refer to the below post for Knuth Shuffle.
https://focalpoint.tistory.com/253
class Solution:
def __init__(self, nums: List[int]):
self.nums = nums
def reset(self) -> List[int]:
return self.nums
def shuffle(self) -> List[int]:
import copy
import random
self.temp = copy.deepcopy(self.nums)
for i in range(len(self.temp)-1):
j = random.randint(i, len(self.temp)-1)
self.temp[i], self.temp[j] = self.temp[j], self.temp[i]
return self.temp
# Your Solution object will be instantiated and called as such:
# obj = Solution(nums)
# param_1 = obj.reset()
# param_2 = obj.shuffle()
'Computer Science > Coding Test' 카테고리의 다른 글
LeetCode: 454. 4Sum II (0) | 2022.01.16 |
---|---|
LeetCode: 395. Longest Substring with At Least K Repeating Characters (0) | 2022.01.16 |
LeetCode: 378. Kth Smallest Element in a Sorted Matrix (0) | 2022.01.14 |
LeetCode: 341. Flatten Nested List Iterator (0) | 2022.01.13 |
LeetCode: 334. Increasing Triplet Subsequence (0) | 2022.01.11 |