fix23([1, 2, 3]) → [1, 2, 0]
fix23([2, 3, 5]) → [2, 0, 5]
fix23([1, 2, 1]) → [1, 2, 1]
Answer 1
public int[] fix23(int[] nums) {
if(nums[0]==2 && nums[1]==3) nums[1] = 0;
if(nums[1]==2 && nums[2]==3) nums[2] = 0;
return nums;
}
Answer 2
public int[] fix23(int[] nums) {
if (nums[0] == 2 && nums[1] == 3)
nums[1] = 0;
if (nums[1] == 2 && nums[2] == 3)
nums[2] = 0;
return new int[] {nums[0],nums[1],nums[2]};
}
No comments :
Post a Comment