zoukankan      html  css  js  c++  java
  • Java for LeetCode 189 Rotate Array

    Rotate an array of n elements to the right by k steps.

    For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].

    解题思路:

    JAVA实现如下:

        public void rotate(int[] nums, int k) {
            k%=nums.length;
            k=nums.length-k;
            int[] nums2=new int[k];
            for(int i=0;i<k;i++)
            	nums2[i]=nums[i];
            for(int i=0;i<nums.length-k;i++)
            	nums[i]=nums[i+k];
            for(int i=0;i<k;i++)
            	nums[nums.length-k+i]=nums2[i];
        }
    
  • 相关阅读:
    json
    封装PDO
    PDO
    jquery练习
    jquery包
    jquery
    租房子 多条件查询
    查询
    新闻修改处理页面
    新闻添加数据
  • 原文地址:https://www.cnblogs.com/tonyluis/p/4557341.html
Copyright © 2011-2022 走看看