题解 | #向左移动牛群#

向左移动牛群

https://www.nowcoder.com/practice/e70fc604c3684ce294e6af5e97feff04

import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param nums int整型一维数组 
     * @param k int整型 
     * @return int整型一维数组
     */
    public int[] rotateCows (int[] nums, int k) {
        int len=nums.length;
        int t;
        for(int i=0;i<k;i++){
            t=nums[len-1];
            for(int j=len-1;j>0;j--){
                nums[j]=nums[j-1];
            }
            nums[0]=t;
            // System.out.println(Arrays.toString(nums));
        }
        return nums;
    }
}

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务