Skip to content

Instantly share code, notes, and snippets.

@Toltar
Created December 13, 2016 14:26
Show Gist options
  • Save Toltar/180490027621376a77f108c9fd81421f to your computer and use it in GitHub Desktop.
Save Toltar/180490027621376a77f108c9fd81421f to your computer and use it in GitHub Desktop.
Left array Rotation
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int a[] = new int[n];
for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
}
String resultString = Arrays.toString(leftRotation(a,k));
resultString = resultString.replaceAll("(,)||( ,)", "").replaceAll("\\[", "").replaceAll("\\]", "");
System.out.println(resultString);
}
public static int[] leftRotation(int[] arr, int d, int n){
for(int y = 0; y < d; y++){
for(int x = 0; x < arr.length - 1; x++){
int tmp = arr[x];
arr[x] = arr[x+1];
arr[x+1] = tmp;
}
}
return arr;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment