Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Test {
- public static void main(String[] args) {
- int array[] = { 4, 8, 9, 5, 1 }; // 9 5 1 4 8
- Solution1 s = new Solution1();
- s.rotateLeft(array,2);
- }
- }
- class Solution1 {
- public int[] rotateLeft(int a[],int x) {
- int a1[] = new int[a.length];
- int k = (a.length + 1) - x;
- int j=0;
- int temp[] = new int[x-1];
- /*
- for(int r=0; r <=k; r++)
- {
- temp[r]=a[k];
- k--;
- }
- */
- for(int i=x ;i<a.length; i++) //i=0 ; 1<4
- {
- a1[j]= a[i];
- j++;
- }
- for (int i : a1)
- {
- System.out.print(i + " ");
- }
- return a;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement