## Problem:

Given an array of ints, return true if the array contains a 2 next to a 2 or a 4 next to a 4, but not both.

either24({1, 2, 2}) → true
either24({4, 4, 1}) → true
either24({4, 4, 1, 2, 2}) → false

## Solution:

public boolean either24(int[] nums) {
boolean found2 = false;
boolean found4 = false;

for (int i = 0;i < nums.length; i++) {
if (nums[i] == 2 && i < nums.length-1 && nums.length > 1 && nums[i+1] == 2)
found2 = true;
if (nums[i] == 4 && i < nums.length-1 && nums.length > 1 && nums[i+1] == 4)
found4 = true;
}

if (found2 && found4)
return false;
else if (!found2 && !found4)
return false;
else
return true;

}

1. public boolean either24(int[] nums) {
boolean esta = false;
boolean dos = false;
boolean cuatro = false;

for(int i=0; i<nums.length-1; i++)
{

if(nums[i]==4 && nums[i+1]==4)
{
esta = true;
cuatro=true;
}

if(nums[i]==2 && nums[i+1]==2)
{
esta = true;
dos=true;
}

if(dos && cuatro)
{
esta = false;
break;
}
}

return esta;
}

2. public boolean either24(int[] nums) {
boolean fours=false;
boolean twos=false;

for(int i=0;i<=nums.length-2;i++){
if(nums[i]==2 && nums[i+1]==2){
twos=true;
}

else if(nums[i]==4 && nums[i+1]==4){
fours=true;
}

}

if(fours && twos){
return false;
}
if(!fours && !twos){
return false;
}

else return true;

}

3. I think that my solution is easier..
public boolean either24(int[] nums) {
boolean war2 = false;
boolean war4 = false;

for (int i = 0; i < nums.length-1; i++)
{
if (nums[i] == 2 && nums[i+1] == 2)
war2 = true;
if (nums[i] == 4 && nums[i+1] == 4)
war4 = true;
}
if (war2 == war4)
return false;
else
return true;
}

4. A better Version :
public boolean either24(int[] nums) {
boolean zwei =false;
boolean vier = false;
for(int i =0; i<nums.length - 1; i++){

if(nums[i]== 2 && nums[i + 1]==2){
zwei =true;
}
if(nums[i]== 4 && nums[i + 1]== 4){
vier =true;
}

}
if(vier==true ^ zwei == true){
return true;
}

return false;

}

5. public boolean either24(int[] nums) {

boolean two = false;
boolean four = false;

for(int i = 0; i < nums.length-1; i++) {

if (nums[i] == 2 && nums[i+1] == 2) two = true;
if (nums[i] == 4 && nums[i+1] == 4) four = true;

}return two ^ four;

}

6. if(Arrays.toString(nums).contains("2, 2")&&Arrays.toString(nums).contains("4, 4"))
return false;
if(Arrays.toString(nums).contains("2, 2")||Arrays.toString(nums).contains("4, 4"))
return true;
return false;

7. public boolean either24(int[] nums) {
boolean twotwo=false;
boolean fourfour= false;
for(int i = 0;i<nums.length -1;i++){
if (nums[i]==2 && nums[i+1]==2){
twotwo=true;
}
if (nums[i]==4 && nums[i+1] ==4){
fourfour = true;
}
}
if( twotwo && fourfour) {
return false;
}
return (twotwo || fourfour);
}

8. String arrS = Arrays.toString(nums).replaceAll("\$|,|\$|\\s","");
boolean isTrue =
(arrS.contains("22")&&!arrS.contains("44"))?true:
(arrS.contains("44")&&!arrS.contains("22"))?true:false;
return isTrue;

9. int c2=0,c4=0;
for(int i=0;i0 && c4==0) || (c4>0 && c2==0);

1. int c2=0,c4=0;
for(int i=0;i0 && c4==0) || (c4>0 && c2==0);

10. doesn't let me to share whole code(?)

11. public boolean either24(int[] nums) {
int four =0;
int two= 0;
for(int i=0; i0 && two==0) {
return true;
}

else if(two>0 && four==0) {
return true;
}

else{
return false;
}
}

12. public boolean either24(int[] nums) {
int four =0;
int two= 0;
for(int i=0; i0 && two==0) {
return true;
}

else if(two>0 && four==0) {
return true;
}

else{
return false;
}
}

13. public boolean either24(int[] nums) {
if (Arrays.toString(nums).contains("2, 2")) {
if (Arrays.toString(nums).contains("4, 4")) {
return false;
}
}
return Arrays.toString(nums).contains("2, 2")
|| Arrays.toString(nums).contains("4, 4");
}

14. public boolean either24(int[] nums) {
return Arrays.toString(nums).contains("2, 2") != Arrays.toString(nums).contains("4, 4");
}

15. public boolean either24(int[] nums) {
return Arrays.toString(nums).contains("2, 2") != Arrays.toString(nums).contains("4, 4");
}

16. public boolean either24(int[] nums) {
boolean is2 = false;
boolean is4 = false;

for(int i = 0; i<nums.length-1;i++){
if(nums[i]==2 && nums[i+1]==2){
is2 = true;
}
else if(nums[i]==4 && nums[i+1]==4){
is4 = true;
}
}

if(is2 && is4){
return false;
}else if( !is2 & !is4){
return false;
}else {
return true;
}

}