Java solution ,easy to understand (I think so...


  • 1
    Z

    public class Solution {

    public void rotate(int[] nums, int k) {
    
       int size=nums.length;
      
       //拷贝一份数据 a copy of the data
       int [] list=new int[size];
       
       for(int i=0;i<size;i++){
          
           list[i]=nums[i];
       }
       
       for(int i=0;i<size;i++){
           nums[(i+k)%size]=list[i];
       }
    

    }


Log in to reply
 

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