FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Leetcode-JavaScript/Rotate Array.js at master · parshva45/Leetcode-JavaScript · GitHub
parshva45
/
Leetcode-JavaScript
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Leetcode-JavaScript
/
Rotate Array.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
16 lines (14 loc) · 435 Bytes
Breadcrumbs
Leetcode-JavaScript
/
Rotate Array.js
Copy path
File metadata and controls
16 lines (14 loc) · 435 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
/*Rotate an array of n elements to the right by k steps.
For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].*/
/**
*
@param
{
number[]
} nums
*
@param
{
number
} k
*
@return
{
void
} Do not return anything, modify nums in-place instead.
*/
var
rotate
=
function
(
nums
,
k
)
{
k
=
k
%
nums
.
length
for
(
i
=
0
;
i
<
k
;
i
++
)
{
last
=
nums
.
pop
(
nums
.
length
-
1
)
nums
.
unshift
(
last
)
}
}
;
Back
|
FazBrowse Home
|
New Git URL