描述
给出两个整数 aa 和 bb , 求他们的和并以整数(int)的形式返回。
你不需要从标准输入流读入数据,只需要根据aplusb
传入的两个参数 a 和 b,计算他们的和并返回就行。
样例
样例 1:
输入:
a = 1
b = 2
输出:
3
解释:
a + b = 1 + 2 = 3
样例 2:
输入:
a = -1
b = 1
输出:
0
解释:
a + b = -1 + 1 = 0
挑战
显然你可以直接返回 a + b,但是你是否可以挑战不这样做?(不使用+
等算数运算符)
Go语言:
/**
* @param a: An integer
* @param b: An integer
* @return: The sum of a and b
*/
func Aplusb(a int, b int) int {
// write your code here
return a+b
}
Accepted 100%
41 ms时间消耗 5.38 MB空间消耗 您的提交打败了88.40 %的提交
Python 3:
class Solution:
"""
@param a: An integer
@param b: An integer
@return: The sum of a and b
"""
def aplusb(self, a: int, b: int) -> int:
# write your code here
return (a+b)
Accepted 100%
81 ms时间消耗 6.00 MB空间消耗 您的提交打败了98.20 %的提交
Rust:
pub struct Solution;
impl Solution {
// @param a: An integer
// @param b: An integer
// @return: The sum of a and b
pub fn aplusb(a: i32, b: i32) -> i32 {
// write your code here
return a+b;
}
}
Accepted 100%
41 ms时间消耗 5.57 MB空间消耗 您的提交打败了100.00 %的提交