Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

makeLast challenge

Hi,

I am trying


http://codingbat.com/prob/p137188

public int[] makeLast(int[] nums) {

int len= nums.length;
int lenNew=2*len;


int numsNew[]=new int[lenNew];
numsNew[lenNew-1]=nums[len-1];

for(int i=0;i<lenNew-1;i++)
{
numsNew[i]=0;
}
return numsNew;
  
}

Open in new window


I passed alll the tests. How do i improve above code. please advise
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Slight variation of ozo's solution (no points)
            int[] array = new int[2*nums.length];
            array[array.length -1] = nums[nums.length - 1];
            return array;