FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
LeetCode-Solutions/Python/shuffle-an-array.py at master · Monika-R/LeetCode-Solutions · GitHub
Monika-R
/
LeetCode-Solutions
Public
forked from
kamyu104/LeetCode-Solutions
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
LeetCode-Solutions
/
Python
/
shuffle-an-array.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
38 lines (26 loc) · 687 Bytes
Breadcrumbs
LeetCode-Solutions
/
Python
/
shuffle-an-array.py
Copy path
File metadata and controls
38 lines (26 loc) · 687 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
32
33
34
35
# Time: O(n)
# Space: O(n)
import
random
class
Solution
(
object
):
def
__init__
(
self
,
nums
):
"""
:type nums: List[int]
:type size: int
"""
self
.
__nums
=
nums
def
reset
(
self
):
"""
Resets the array to its original configuration and return it.
:rtype: List[int]
"""
return
self
.
__nums
def
shuffle
(
self
):
"""
Returns a random shuffling of the array.
:rtype: List[int]
"""
nums
=
list
(
self
.
__nums
)
for
i
in
xrange
(
len
(
nums
)):
j
=
random
.
randint
(
i
,
len
(
nums
)
-
1
)
nums
[
i
],
nums
[
j
]
=
nums
[
j
],
nums
[
i
]
return
nums
Back
|
FazBrowse Home
|
New Git URL