Skip to content

Commit 3f2ba97

Browse files
authored
Create 1-bit-and-2-bit-characters.cpp
1 parent 5ffde1f commit 3f2ba97

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

C++/1-bit-and-2-bit-characters.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
bool isOneBitCharacter(vector<int>& bits) {
7+
auto parity = 0;
8+
for (int i = static_cast<int>(bits.size()) - 2;
9+
i >= 0 && bits[i]; --i) {
10+
parity ^= bits[i];
11+
}
12+
return parity == 0;
13+
}
14+
};

0 commit comments

Comments
 (0)