-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99b6983
commit 8692451
Showing
12 changed files
with
154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
int* decode(int* encoded, int encodedSize, int first, int* returnSize) { | ||
int* arr = (int*)malloc(sizeof(int) * (encodedSize + 1)); | ||
*returnSize = encodedSize + 1; | ||
arr[0] = first; | ||
for (int i = 0; i < encodedSize; i++) | ||
arr[i + 1] = arr[i] ^ encoded[i]; | ||
return arr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
int xorOperation(int n, int start) { | ||
int i, res = start; | ||
for (i = 1; i < n; i++) | ||
start += 2, res ^= start; | ||
return res; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
#include "vector" | ||
#include "iostream" | ||
using namespace std; | ||
|
||
class Solution { | ||
public: | ||
vector<int> decode(vector<int>& encoded, int first) { | ||
int size = encoded.size(); | ||
vector<int> result(size + 1); | ||
result[0] = first; | ||
for (int i = 0; i < size; i++) | ||
result[i + 1] = result[i] ^ encoded[i]; | ||
return result; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
class Solution { | ||
public: | ||
int xorOperation(int n, int start) { | ||
int i, res = start; | ||
for (i = 1; i < n; i++) | ||
start += 2, res ^= start; | ||
return res; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
class Solution { | ||
public int[] decode(int[] encoded, int first) { | ||
int size = encoded.length; | ||
int[] result = new int[size + 1]; | ||
result[0] = first; | ||
for (int i = 0; i < size; i++) | ||
result[i + 1] = result[i] ^ encoded[i]; | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
|
||
class Solution { | ||
public int xorOperation(int n, int start) { | ||
int i, res = start; | ||
for (i = 1; i < n; i++){ | ||
start += 2; res ^= start; | ||
} | ||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
/** | ||
* @param {number[]} encoded | ||
* @param {number} first | ||
* @return {number[]} | ||
*/ | ||
var decode = function (encoded, first) { | ||
let result = [first] | ||
let size = encoded.length | ||
for (let i = 0; i < size; i++) | ||
result.push(result[i] ^ encoded[i]) | ||
return result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
/** | ||
* @param {number} n | ||
* @param {number} start | ||
* @return {number} | ||
*/ | ||
var xorOperation = function (n, start) { | ||
let i, res = start | ||
for (i = 1; i < n; i++) | ||
start += 2, res ^= start | ||
return res | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# by @codeAbinash | ||
# Time : O(n) | ||
# Space : O(1) | ||
|
||
class Solution: | ||
def decode(self, encoded: List[int], first: int) -> List[int]: | ||
decoded = [first] | ||
for i in range(len(encoded)): | ||
decoded.append(encoded[i] ^ decoded[i]) | ||
return decoded |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# by @codeAbinash | ||
# Time : O(n) | ||
# Space : O(1) | ||
|
||
class Solution: | ||
def xorOperation(self, n: int, start: int) -> int: | ||
res = start; | ||
for i in range(1,n): | ||
res ^= start + 2*i | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
function decode(encoded: number[], first: number): number[] { | ||
let arr = [first]; | ||
let size = encoded.length | ||
for (let i = 0; i < size; i++) | ||
arr.push(encoded[i] ^ arr[i]) | ||
return arr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// by @codeAbinash | ||
// Time : O(n) | ||
// Space : O(1) | ||
|
||
function xorOperation(n: number, start: number): number { | ||
let res = start | ||
for (let i = 1; i < n; i++) | ||
start += 2, res ^= start | ||
return res | ||
} |