MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / rotate

Function rotate

javascript/0189-rotate-array.js:10–17  ·  view source on GitHub ↗
(nums, k)

Source from the content-addressed store, hash-verified

8 * @return {void} Do not return anything, modify nums in-place instead.
9 */
10var rotate = function (nums, k) {
11 // if the k exceeds the length of nums.
12 k = k % nums.length;
13
14 nums.reverse();
15 reversePortionOfArray(nums, 0, k - 1);
16 reversePortionOfArray(nums, k, nums.length - 1);
17};
18
19var reversePortionOfArray = function (nums, start, end) {
20 while (start < end) {

Callers

nothing calls this directly

Calls 2

reversePortionOfArrayFunction · 0.85
reverseMethod · 0.45

Tested by

no test coverage detected