Created
July 16, 2016 19:32
-
-
Save jianminchen/7e934805e2bfa9fe4ce79f3991a4b570 to your computer and use it in GitHub Desktop.
bulbs - facebook code lab - correct answer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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