Advertisement
kilya

Rotate Array - Java

Jun 27th, 2020
1,657
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.28 KB | None | 0 0
  1. public void rotate(int[] nums, int k) {
  2.     int temp, previous;
  3.     for (int i = 0; i < k; i++) {
  4.       previous = nums[nums.length - 1];
  5.       for (int j = 0; j < nums.length; j++) {
  6.         temp = nums[j];
  7.         nums[j] = previous;
  8.         previous = temp;
  9.       }
  10.     }
  11.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement