Maintain the state for each index in stat, and return the on one in the end.
Code
class Solution {
public:
vector<int> toggleLightBulbs(vector<int>& bulbs) {
vector<bool> stat(101, false);
for(const auto& b: bulbs) {
stat[b] = !stat[b];
}
vector<int> ans;
for(int i = 1 ; i <= 100; ++i) {
if(stat[i]) ans.push_back(i);
}
return ans;
}
};