circular left shift of an array by n positions in java

前端 未结 12 2348
醉梦人生
醉梦人生 2020-12-31 20:16

I am trying to do the circular left shift of an array by n positions using only a single 1D array. I can do it in two arrays, but I haven\'t figured out how to do it using o

12条回答
  •  梦毁少年i
    2020-12-31 20:55

    Maybe an old post.. but here you are my solution (where A obviously is the array and K the number of positions).

    public int[] solution(int[] A, int K){
        int[] result = new int[A.length];
    
        for (int i = 0; i

提交回复
热议问题