1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| class Solution { public int[] decode(int[] encoded) { int n = encoded.length; int[] arr = new int[n+1]; int total = 0; for(int i = 1; i <= n+1; i ++){ total ^= i; }
int tmp = 0; for(int i = 1; i < n; i = i + 2){ tmp ^= encoded[i]; }
arr[0] = total ^ tmp; for(int i = 1; i <= n; i++){ arr[i] = arr[i-1] ^ encoded[i-1]; } return arr; } }
|