<p>Given two numbers <code>arr1</code> and <code>arr2</code> in base <strong>-2</strong>, return the result of adding them together.</p>

<p>Each number is given in <em>array format</em>:&nbsp; as an array of 0s and 1s, from most significant bit to least significant bit.&nbsp; For example, <code>arr = [1,1,0,1]</code> represents the number <code>(-2)^3&nbsp;+ (-2)^2 + (-2)^0 = -3</code>.&nbsp; A number <code>arr</code> in <em>array, format</em> is also guaranteed to have no leading zeros: either&nbsp;<code>arr == [0]</code> or <code>arr[0] == 1</code>.</p>

<p>Return the result of adding <code>arr1</code> and <code>arr2</code> in the same format: as an array of 0s and 1s with no leading zeros.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> arr1 = [1,1,1,1,1], arr2 = [1,0,1]
<strong>Output:</strong> [1,0,0,0,0]
<strong>Explanation: </strong>arr1 represents 11, arr2 represents 5, the output represents 16.
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> arr1 = [0], arr2 = [0]
<strong>Output:</strong> [0]
</pre>

<p><strong class="example">Example 3:</strong></p>

<pre>
<strong>Input:</strong> arr1 = [0], arr2 = [1]
<strong>Output:</strong> [1]
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= arr1.length,&nbsp;arr2.length &lt;= 1000</code></li>
	<li><code>arr1[i]</code>&nbsp;and <code>arr2[i]</code> are&nbsp;<code>0</code> or <code>1</code></li>
	<li><code>arr1</code> and <code>arr2</code> have no leading zeros</li>
</ul>

class Solution:
    def addNegabinary(self, arr1: List[int], arr2: List[int]) -> List[int]:
        # 將負二進制轉換為十進制
        def to_decimal(arr: List[int]) -> int:
            result = 0
            for i, digit in enumerate(reversed(arr)):  # 反轉後方便計算
                result += digit * ((-2) ** i)  # 計算 (-2)^i 的值
            return result
        
        # 將十進制轉換回負二進制
        def to_negabinary(num: int) -> List[int]:
            if num == 0:
                return [0]
            result = []
            while num != 0:
                remainder = num % (-2)
                num //= (-2)
                if remainder < 0:  # 如果餘數為負數，進位並修正餘數
                    remainder += 2
                    num += 1
                result.append(remainder)
            return result[::-1]  # 結果是逆序的，返回時要反轉

        # 將 arr1 和 arr2 轉換為十進制數字，然後加總
        decimal_sum = to_decimal(arr1) + to_decimal(arr2)

        # 將加總後的結果轉換回負二進制並返回
        return to_negabinary(decimal_sum)

16800