## Problem:

Given an array of ints, return true if the array contains two 7's next to each other, or there are two 7's separated by one element, such as with {7, 1, 7}.

has77({1, 7, 7}) → true
has77({1, 7, 1, 7}) → true
has77({1, 7, 1, 1, 7}) → false

## Solution:

public boolean has77(int[] nums) {
boolean result = false;

for (int i = 0; i < nums.length-1; i++)
if ((nums[i] == 7 && nums[i+1] == 7))
result = true;

for (int i = 0; i < nums.length-2; i++)
if ((nums[i] == 7 && nums[i+2] == 7))
result = true;


1. Why pass through twice?

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

2. public boolean has77(int [] nums){
for(int x = 0; x < nums.length-2; x++){
if(int[x] == 7 && int[x+1] == 7){
return true;
}
if(int[x] == 7 && int [x+2] == 7){
return true;
}
if(int[x+1] == 7 && int [x+2] == 7){
return true;
}
}
return false;
}

3. public boolean has77(int[] nums) {
boolean result = false;

for (int i = 0; i < nums.length-1; i++)
if ((nums[i] == 7 && nums[i+1] == 7))
result = true;

for (int i = 0; i < nums.length-2; i++)
if ((nums[i] == 7 && nums[i+2] == 7))
result = true;
return result;
}

4. public boolean has77(int[] nums) {
boolean flag = false;

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

5. public boolean has77(int[] nums) {
for(int i=1;i<nums.length;i++){
if(nums[i]==7 && nums[i-1]==7){
return true;
}else if(i<nums.length-1 && nums[i-1]==7 && nums[i]!=7 && nums[i+1]==7){
return true;
}
}
return false;
}

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

7. public boolean has77(int[] nums) {
for(int i=0; i<nums.length;i++){
if(i+1<nums.length && nums[i]==7 && nums[i+1]==7 ){
return true;
}

else if(i+2<nums.length && nums[i]==7 && nums[i+2]==7 ){
return true;
}
}

return false;
}

8. public boolean has77(int[] nums) {
boolean bool = false;

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

9. public boolean has77(int[] nums) {
boolean b = false;
for (int i = 0; i < nums.length - 2; i++)
if ((nums[i] == 7 && nums[i] == nums[i+1]) || ((nums[i] == 7 && nums[i] != nums[i+1]) && nums[i] == nums[i+2]) || (nums[i] != 7 && nums[i+1] == 7) && nums[i+1] == nums[i+2])
b = true;
return b;
}

10. public static boolean has77(int[] nums) {
int len = nums.length;
boolean sevens = false;
for(int i=0; i<len-1; i++){
if(nums[i]==7){
if(nums[i+1]==7 || (i<(len-2) && nums[i+2]==7)){
sevens = true;
}
}
}
return sevens;

}

11. public boolean has77(int[] nums)
{

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

return false;
}

12. public boolean has77(int[] nums) {
int found = -3;
for(int i = 0; i < nums.length; i++){
if(nums[i] == 7){
if(i - found <= 2){
return true;
}
found = i;
}
}
return false;
}

13. This is mine. Tell me if there is a more simple way.

public boolean has77(int[] nums) {
boolean match = false;
for (int i = 1;i<nums.length-1;i++){
if((nums[i]==7 && nums[i+1]==7)||(nums[i-1]==7 && nums[i+1]==7)||(nums[i]==7 && nums[i-1]==7)){
match =true;
}
}
return match;
}