Skip to content

Commit ff1f532

Browse files
committed
A + B 问题
1 parent 88319c3 commit ff1f532

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

a_b_problem.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
"""
5+
@param a: The first integer
6+
@param b: The second integer
7+
@return: The sum of a and b
8+
"""
9+
def aplusb(self, a, b):
10+
# write your code here, try to do it without arithmetic operators.
11+
import ctypes
12+
a = ctypes.c_int32(a).value
13+
b = ctypes.c_int32(b).value
14+
while b != 0:
15+
carry = ctypes.c_int32(a & b).value
16+
a = ctypes.c_int32(a ^ b).value
17+
b = ctypes.c_int32(carry << 1).value
18+
return a

0 commit comments

Comments
 (0)