does anyone can help me explain this line of Java Solusion?


  • 0
    L
    public static void rotate(int[] nums, int k){
        int[] result=new int[nums.length];
        for(int i=0;i<nums.length;i++){ 
        result[(i+k) % nums.length] = nums[i];// This line is pretty confused  why we need i+k and % nums.length , does some one can help me explain more specific ? Thank you so much
        }
    
        for(int i=0;i<nums.length;++i){
        nums[i]=result[i];
        System.out.print(nums[i]);
        }
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.