Problem:
Given an array of ints, return true if the array is length 1 or more, and the first element and the last element are equal.
sameFirstLast({1, 2, 3}) → false
sameFirstLast({1, 2, 3, 1}) → true
sameFirstLast({1, 2, 1}) → true
Solution:
public boolean sameFirstLast(int[] nums) { if (nums.length >= 1 && nums[0] == nums[nums.length-1]) return true; else return false; }
warmup1 solution are not working
ReplyDeleteThis comment has been removed by the author.
ReplyDeletepublic boolean sameFirstLast(int[] nums) {
ReplyDeleteif (nums.length == 0 || nums[0] != nums[nums.length - 1]){
return false;
}
return true;
}
public boolean sameFirstLast(int[] nums) {
ReplyDeletereturn (nums.length != 0) && (nums[0] == nums[nums.length - 1]);
}
public boolean sameFirstLast(int[] nums) {
ReplyDeleteif (nums.length==0)return false;
if (nums[0]==nums[nums.length-1]) return true ;
else return false ;
}
public boolean sameFirstLast(int[] nums)
ReplyDelete{
if((nums.length)!=0)
{
if(nums[0]==nums[nums.length-1])
return true;
}
return false;
}
if (nums.length = 1 && nums[0] == nums[nums.length -1]){
return true;
}else{
return false;
}
}
public boolean sameFirstLast(int[] nums) {
Deleteif (nums.length == 1 && nums[0] == nums[nums.length -1]){
return true;
}else{
return false;
}
}