Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created July 16, 2016 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/7e934805e2bfa9fe4ce79f3991a4b570 to your computer and use it in GitHub Desktop.
Save jianminchen/7e934805e2bfa9fe4ce79f3991a4b570 to your computer and use it in GitHub Desktop.
bulbs - facebook code lab - correct answer
public class Solution {
public int bulbs(List<Integer> a) {
if(a == null || a.size() == 0)
return 0;
int count = 0;
int index = 0;
while(a !=null && index < a.size())
{
Integer previous = a.get(index);
boolean isEven = count%2 == 0;
boolean previousIsEven = previous.intValue()%2 ==0;
if((isEven && previousIsEven) ||(!isEven && !previousIsEven))
{
count ++;
}
index++;
}
return count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment