Horje
rotate an array of n elements to the right by k steps Code Example
rotate an array of n elements to the right by k steps
public void rotate(int[] nums, int k) {
        k %= nums.length;
        reverse(nums, 0, nums.length - 1);
        reverse(nums, 0, k - 1);
        reverse(nums, k, nums.length - 1);
    }
    public void reverse(int[] nums, int start, int end) {
        while (start < end) {
            int temp = nums[start];
            nums[start] = nums[end];
            nums[end] = temp;
            start++;
            end--;
        }
    }




Cpp

Related
break statement in c++ program Code Example break statement in c++ program Code Example
error: use of parameter outside function body before ] token c++ Code Example error: use of parameter outside function body before ] token c++ Code Example
the question for me Code Example the question for me Code Example
if else c++ Code Example if else c++ Code Example
how to type a vertical stack program c++ Code Example how to type a vertical stack program c++ Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7