Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Created September 3, 2015 12:50
Show Gist options
  • Save mirsahib/1a02f558d7650164ef81 to your computer and use it in GitHub Desktop.
Save mirsahib/1a02f558d7650164ef81 to your computer and use it in GitHub Desktop.
[Java]Codingbat-> Array-2 -> twoTwo
public boolean twoTwo(int[] nums) {
int len =nums.length;
boolean result = true;
for(int i =0;i<len-1;i++){
if(len<=1 && nums[0]!=2)return true;
if(len>=2){
if(nums[len-1]==2 && nums[len-2]!=2)result=false;
}
if(nums[i]==2 && nums[i+1]==2)result = true;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment