Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created July 16, 2016 19:43
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/7857bba5138d6c72067eddf40f0f5d5b to your computer and use it in GitHub Desktop.
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
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