題目描述:
寫一個函數,求兩個整數之和,要求在函數體內不得使用 “+”、“-”、“*”、“/” 四則運算符號。
示例:
輸入: a = 1, b = 1
輸出: 2
思路:位運算
class Solution(object):
def add(self, a, b):
"""
:type a: int
:type b: int
:rtype: int
"""
#
return (a^b) +((a&b)<<1)