栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

1 · A + B 问题(LintCode,算法,入门)

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

1 · A + B 问题(LintCode,算法,入门)

描述

给出两个整数 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语言:

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 %的提交

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/921228.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号