You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Given an array, rotate the array to the right by k steps, where k is non-negative.
/** * @param {number[]} nums * @param {number} k * @return {void} Do not return anything, modify nums in-place instead. */varrotate=function(nums,k){k%=nums.length// if k is greater than nums.length then one cycle is completed that means it will remain the same and we have to remainder shiftsletreverse=function(i,j){while(i<j){[nums[i],nums[j]]=[nums[j],nums[i]];i++;j--;}}// suppose ----->---> reverse(0,nums.length-1);// reverse <--<------reverse(0,k-1)// reverse first part ---><----reverse(k,nums.length-1)// reverse second part --->----->};
The text was updated successfully, but these errors were encountered:
Given an array, rotate the array to the right by k steps, where k is non-negative.
The text was updated successfully, but these errors were encountered: