1073. Adding Two Negabinary Numbers

原题&翻译

Given two numbers arr1 and arr2 in base -2, return the result of adding them together.
给出两个 -2 进制的数字 arr1, arr2, 返回两数相加的结果.

Each number is given in array format: as an array of 0s and 1s, from most significant bit to least significant bit. For example, arr = [1,1,0,1] represents the number (-2)^3 + (-2)^2 + (-2)^0 = -3. A number arr in array format is also guaranteed to have no leading zeros: either arr == [0] or arr[0] == 1.
给出的数字格式都为数组: 从最高位到最低位都由 0 和 1 构成. 例如, arr = [1,1,0,1] 代表 (-2)^3 + (-2)^2 + (-2)^0 = -3. 表示数字的数组中确保没有前导零: arr == [0] 或者 arr[0] == 1

Return the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.
返回的结果也不允许存在前导零

Example 1:


解题

两数相加而已, 由于是负数进制, 就会有负的进位, 这里来的借位需要好好思量

via: https://leetcode.com/problems/adding-two-negabinary-numbers/

Hello world!
文章已创建 209

相关文章

开始在上面输入您的搜索词,然后按回车进行搜索。按ESC取消。

返回顶部