Advertisement
Guest User

Solution

a guest
Nov 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. // Complete the rotLeft function below.
  2.     static int[] rotLeft(int[] a, int d) {
  3.         for(int i = 0; i < d; i++){
  4.             int lastIndex = a.length - 1;
  5.  
  6.             //Hold first element
  7.             int temp = a[0];
  8.             for(int index = 0; index < lastIndex; index++){
  9.                 a[index] = a[index + 1];
  10.             }
  11.  
  12.             //Set last element to the prev first
  13.             a[lastIndex] = temp;
  14.         }
  15.  
  16.         return a;
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement