1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
struct Solution; impl Solution { fn get_sum(a: i32, b: i32) -> i32 { if b == 0 { a } else { Self::get_sum(a ^ b, (a & b) << 1) } } } #[test] fn test() { assert_eq!(Solution::get_sum(1, 2), 3); assert_eq!(Solution::get_sum(-2, 3), 1); }