Skip to content

Commit 0b631bd

Browse files
authored
Create decode-xored-array.cpp
1 parent c81c448 commit 0b631bd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

C++/decode-xored-array.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
vector<int> decode(vector<int>& encoded, int first) {
7+
vector<int> result = {first};
8+
for (const auto& x: encoded) {
9+
result.emplace_back(result.back() ^ x);
10+
}
11+
return result;
12+
}
13+
};

0 commit comments

Comments
 (0)