Created
July 16, 2016 19:43
-
-
Save jianminchen/7857bba5138d6c72067eddf40f0f5d5b to your computer and use it in GitHub Desktop.
bulbs - facebook code lab - answer provided from the lab - standard and elegant one
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
class Solution { | |
public: | |
int bulbs(vector<int> &A) { | |
int state= 0, ans = 0; | |
for (int i = 0;i < A.size();i++) { | |
if (A[i] == state) { | |
ans++; | |
state = 1 - state; | |
} | |
} | |
return ans; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment