sameFirstLast([1, 2, 3]) → false
sameFirstLast([1, 2, 3, 1]) → true
sameFirstLast([1, 2, 1]) → tru
Answer 1:
public boolean sameFirstLast(int[] nums) {
return nums.length>=1 && nums[0]==nums[nums.length-1];
}
Answer 2:
public boolean sameFirstLast(int[] nums) {
if ( nums.length > 0 && nums[0]
== nums[nums.length-1] )
return true;
else
return false;
}
Reference
http://www.javaproblems.com/2012/12/coding-bat-java-array-1-samefirstlast.html
No comments :
Post a Comment