371. Sum of Two Integers--LeetCode Record
Calculate the sum of two integers a and b, but you are not allowed to use the operator + and -.
Example: Given a = 1 and b = 2, return 3.
抓住了一些運算子的特性,題目不難
class Solution {
func getSum(a: Int, _ b: Int) -> Int {
var xor = a ^ b
var and = a & b
and = and << 1
if xor & and != 0 {
return getSum(xor, and)
}
return xor | and
}
}
相關文章
- leetcode 371. Sum of Two IntegersLeetCode
- Leetcode Two SumLeetCode
- Leetcode 1 two sumLeetCode
- Leetcode-Two SumLeetCode
- Two Sum leetcode javaLeetCodeJava
- LeetCode | 1 Two SumLeetCode
- [LeetCode]1.Two SumLeetCode
- LeetCode----1. Two SumLeetCode
- 653-Two Sum IV - Input is a BST
- LeetCode1:Two SumLeetCode
- [LeetCode]1. Two SumLeetCode
- LeetCode OJ : 1 Two SumLeetCode
- LeetCode-1 Two SumLeetCode
- LeetCode: Two sum(兩數之和)LeetCode
- python: leetcode - 1 Two SumPythonLeetCode
- LeetCode Problem-Sum of Two IntegersLeetCode
- JavaScript的two-sum問題解法JavaScript
- [leetCode][013] Two Sum 2LeetCode
- [LeetCode] Two Sum 兩數之和LeetCode
- 349. Intersection of Two Arrays--LeetCode RecordLeetCode
- LeetCode #1:Two Sum(簡單題)LeetCode
- [leetCode][012] Two Sum (1)LeetCode
- Leetcode-1 Two Sum(Java) -by zzyLeetCodeJava
- LeetCode Two Sum(001)解法總結LeetCode
- 350. Intersection of Two Arrays II--LeetCode RecordLeetCode
- python leetcode 之兩數之和(two sum)PythonLeetCode
- LeetCode-Two Sum III - Data structure designLeetCodeStruct
- 【Leetcode】167. Two Sum II - Input array is sortedLeetCode
- 【LeetCode 1_陣列_雜湊表】Two SumLeetCode陣列
- 力扣.1 兩數之和 N 種解法 two-sum力扣
- LeetCode-two sum:python解答陣列問題LeetCodePython陣列
- LeetCode 之 JavaScript 解答第一題 —— 兩數之和(Two Sum)LeetCodeJavaScript
- 2018-08-12 non-adjacent max two-number sum in loop arrayOOP
- 力扣 170. 兩數之和 III - 資料結構設計 two-sum III力扣資料結構
- 力扣 653. 兩數之和 IV 二叉樹/binary-tree two-sum IV力扣二叉樹
- coca after two months vs in two months
- react-recordReact
- GCD SUMGC