Created
July 16, 2016 19:18
-
-
Save jianminchen/7093c5dcd52dd72f1ecd06e1d969e648 to your computer and use it in GitHub Desktop.
bulbs - facebook code lab - need to make solution more efficient on time complexity
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; | |
while(a !=null && a.size()> 0) | |
{ | |
Integer previous = a.get(0); | |
a.remove(0); | |
boolean isEven = count%2 == 0; | |
boolean previousIsEven = previous.intValue()%2 ==0; | |
if((isEven && previousIsEven) ||(!isEven && !previousIsEven)) | |
{ | |
count ++; | |
} | |
} | |
return count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment