Faster method than given in the solution


#1

int Solution::bulbs(vector &A) {
int cnt = 0;
for(int i=0; i<A.size(); i++){
cnt += !((cnt%2)^A[i]);
}
return cnt;
}


#2

The answer given in the solution and yours both are having same linear time complexity.


#3

there is no difference in your solution and given solution :slight_smile:


#4

don’t use modulo operator, use bit manipulation method to make it faster.


#5

Congrats, if someone plugged in a list of size 3 billion, yours would be 0.000001 seconds faster than everyone else’s. It would also take someone else looking at your code 5 more seconds to understand it :+1: