#371

LeetCode:Sum of Two Integers

允我心安 提交于 2019-12-11 16:00:35
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 1、题目名称 Sum of Two Integers(不使用加减法运算符的整数加法) 2、题目地址 https://leetcode.com/problems/sum-of-two-integers/ 3、题目内容 英文: Calculate the sum of two integers a and b , but you are not allowed to use the operator + and - . 中文: 计算两个整数的和,但不允许使用运算符+和- 4、解题方法1 虽然题目中明确表示不让用户使用加法运算符与减法运算符,不过下面两种写法还是能获得Accept: 1)Java代码:直接使用a+b作为返回值 public class Solution { public int getSum(int a, int b) { return a + b; } } 2)Java代码:使用a-(-b)作为返回值 public class Solution { public int getSum(int a, int b) { return a - (-b); } } 5、解题方法2 解题方法1中列举的两种方法虽然能获得Accept,但以这种方式解题明显不是命题人的本意。既然不让用加减法解决两数求和的问题