leetcode算法題–解碼異或后的數組
2021-05-24 17:00 作者:hey_just_do_it | 我要投稿
文章目錄
leetcode算法題--解碼異或后的數組
一、題目
1.示例1
2.示例2
3.提示
4、題目來源
二、代碼
一、題目
????未知 整數數組 arr 由 n 個非負整數組成。經編碼后變?yōu)殚L度為 n - 1 的另一個整數數組 encoded ,其中 encoded[i] = arr[i] XOR arr[i + 1] 。例如,arr = [1,0,2,1] 經編碼后得到 encoded = [1,2,3] 。給你編碼后的數組 encoded 和原數組 arr 的第一個元素 first(arr[0])。請解碼返回原數組 arr ??梢宰C明答案存在并且是唯一的。
1.示例1
????輸入:encoded = [1,2,3], first = 1?
????輸出:[1,0,2,1]?
????解釋:若 arr = [1,0,2,1] ,那么 first = 1 且 encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]
2.示例2
????輸入:encoded = [6,2,7,3], first = 4?
????輸出:[4,2,0,7,4]
3.提示
????1 <= N <= 1000?
????0 <= nums[i] <= 2^16
4、題目來源
????來源:力扣(LeetCode)?
????鏈接:https://leetcode-cn.com/problems/top-k-frequent-words
二、代碼

標簽: