public void rotate4(final int[] nums, int k) {
        final int n = nums.length;
        if (n <= 1) {
            return;
        }
        if (n == k || k == 0) {
            return;
        }
        if (n < k) {
            k = k % n;
        }
        // create a new array length m
        final int m = n - k;
        final int[] tmp = new int[m];
        // store first m elements from nums to the new array
        for (int i = 0; i < m; i++) {
            tmp[i] = nums[i];
        }
        // shift the rest of nums to left
        for (int i = 0; i < k; i++) {
            nums[i] = nums[i + m];
        }
        // store tmp back to nums
        for (int i = 0; i < m; i++) {
            nums[i + k] = tmp[i];
        }
    }