剑指offer
不用加减乘除做加法
相似的企业真题
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 64M,其他语言128M
热度指数:245819
本题知识点:
数学
算法知识视频讲解
校招时部分企业笔试将禁止编程题跳出页面,为提前适应,练习时请使用在线自测,而非本地IDE。
题目描述
写一个函数,求两个整数之和,要求在函数体内不得使用+、-、*、/四则运算符号。
示例1
输入
复制
1,2
1,2
返回值
复制
3
3
上一题
下一题
登录
/
注册
我的提交
编辑器加载中...
public class Solution { public int Add(int num1,int num2) { } }
class Solution { public: int Add(int num1, int num2) { } };
# -*- coding:utf-8 -*- class Solution: def Add(self, num1, num2): # write code here
class Solution { public int Add(int num1, int num2) { // write code here } }
function Add(num1, num2) { // write code here } module.exports = { Add : Add };
function Add(num1, num2) { // write code here }
package main /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param num1 int整型 * @param num2 int整型 * @return int整型 */ func Add( num1 int , num2 int ) int { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # @param num1 int整型 # @param num2 int整型 # @return int整型 # class Solution def Add(num1, num2) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param num1 int整型 * @param num2 int整型 * @return int整型 */ def Add(num1: Int,num2: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param num1 int整型 * @param num2 int整型 * @return int整型 */ fun Add(num1: Int,num2: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param num1 int整型 * @param num2 int整型 * @return int整型 */ public int Add (int num1, int num2) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param num1 int整型 * @param num2 int整型 * @return int整型 */ export function Add(num1: number, num2: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param num1 int整型 * @param num2 int整型 * @return int整型 */ func Add ( _ num1: Int, _ num2: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * @param num1 int整型 * @param num2 int整型 * @return int整型 */ pub fn Add(&self, num1: i32, num2: i32) -> i32 { // write code here } }
1,2
3