Avatar of gudii9
gudii9
Flag 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
JavaProgrammingProgramming Languages-Other

Avatar of undefined
Last Comment
awking00

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ozo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
awking00

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;
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck