Skip to content

Latest commit

 

History

History
124 lines (87 loc) · 1.89 KB

File metadata and controls

124 lines (87 loc) · 1.89 KB

English Version

题目描述

给你两个整数 num1num2,返回这两个整数的和。

 

示例 1:

输入:num1 = 12, num2 = 5
输出:17
解释:num1 是 12,num2 是 5 ,它们的和是 12 + 5 = 17 ,因此返回 17 。

示例 2:

输入:num1 = -10, num2 = 4
输出:-6
解释:num1 + num2 = -6 ,因此返回 -6 。

 

提示:

  • -100 <= num1, num2 <= 100

解法

Python3

class Solution:
    def sum(self, num1: int, num2: int) -> int:
        return num1 + num2

Java

class Solution {
    public int sum(int num1, int num2) {
        return num1 + num2;
    }
}

TypeScript

function sum(num1: number, num2: number): number {
    return num1 + num2;
}

C++

class Solution {
public:
    int sum(int num1, int num2) {
        return num1 + num2;
    }
};

Go

func sum(num1 int, num2 int) int {
	return num1 + num2
}

TypeScript

function sum(num1: number, num2: number): number {
    return num1 + num2;
}

Rust

impl Solution {
    pub fn sum(num1: i32, num2: i32) -> i32 {
        num1 + num2
    }
}

C

int sum(int num1, int num2) {
    return num1 + num2;
}

...