1073. Adding Two Negabinary Numbers Medium
1/**
2 * [1073] Adding Two Negabinary Numbers
3 *
4 * Given two numbers arr1 and arr2 in base -2, return the result of adding them together.
5 * 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.
6 * Return the result of adding arr1 and arr2 in the same format: as an array of 0s and 1s with no leading zeros.
7 *
8 * Example 1:
9 *
10 * Input: arr1 = [1,1,1,1,1], arr2 = [1,0,1]
11 * Output: [1,0,0,0,0]
12 * Explanation: arr1 represents 11, arr2 represents 5, the output represents 16.
13 *
14 * Example 2:
15 *
16 * Input: arr1 = [0], arr2 = [0]
17 * Output: [0]
18 *
19 * Example 3:
20 *
21 * Input: arr1 = [0], arr2 = [1]
22 * Output: [1]
23 *
24 *
25 * Constraints:
26 *
27 * 1 <= arr1.length, arr2.length <= 1000
28 * arr1[i] and arr2[i] are 0 or 1
29 * arr1 and arr2 have no leading zeros
30 *
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/adding-two-negabinary-numbers/
35// discuss: https://leetcode.com/problems/adding-two-negabinary-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40 pub fn add_negabinary(arr1: Vec<i32>, arr2: Vec<i32>) -> Vec<i32> {
41 vec![]
42 }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49 use super::*;
50
51 #[test]
52 fn test_1073() {
53 }
54}
55
Back
© 2025 bowen.ge All Rights Reserved.