Problem:
Given an int array length 2, return true if it does not contain a 2 or 3.
no23({4, 5}) → true
no23({4, 2}) → false
no23({3, 5}) → false
Solution:
public boolean no23(int[] nums) { if (nums[0] != 2 && nums[0] != 3 && nums[1] != 2 && nums[1] != 3) return true; else return false; }
Needs no more then one line of code
ReplyDeletepublic boolean no23(int[] nums) {
ReplyDeletereturn (nums[0]!=2 && nums[0]!=3 && nums[1]!=2 && nums[1]!=3);
}
public boolean no23(int[] nums) {
ReplyDeletereturn !(nums[0]== 2 || nums[0] == 3 || nums[1]== 2 || nums[1] == 3);
}
public boolean no23(int[] nums) {
ReplyDeleteif(nums[0]==2||nums[0]==3){
return false;
}
else
if(nums[1]==2||nums[1]==3){
return false;
}
else {
return true;
}
}