code.ashish.me

Atom feed

Recently added: 02 Count Of Subset Sum, 416 Partition Equal Subset Sum, 01 Subset Sum, 518 Coin Change 2, 983 Minimum Cost For Tickets

Leftrotateanarraybyone

import java.util.Arrays;

/**
 *
 * Ashish Patel
 * e: ashishsushilPatel@gmail.com
 * w: https://ashish.me
 *
 */

class LeftRotateAnArrayByOne {

  static int[] func(int[] nums){
    int temp = nums[0];
    for(int i = 1; i < nums.length; i++) {
      nums[i-1] = nums[i];
    }
    nums[nums.length - 1] = temp;
    return nums;
  }

  public static void main(String[] args){
    int[] nums = { 10, 20, 30, 40, 50 };
    int[] result = func(nums);
    System.out.println(Arrays.toString(result));
  }
}

Created 2021-10-27T15:53:34+01:00 · Edit