定义一个函数,实现输入a,b两个数,返回两数的和,差,乘积,商,余数。然后依次存入切片中,最后返回。 知识点: golang函数支持多个返回值,但函数有多个返回值时,如果其中某个或某几个返回值不想使用,可以通过下划线_来丢弃这些返回值。例如下面的f1函数两个返回值,调用该函数时,丢弃了第二个返回值b,只保留了第一个返回值a赋值给了变量a。
示例1
输入
2,2
输出
[4,0,4,1,0]
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ public int[] operate (int a, int b) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型vector */ vector
operate(int a, int b) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param a int整型 # @param b int整型 # @return int整型一维数组 # class Solution: def operate(self , a , b ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ public List
operate (int a, int b) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ function operate( a , b ) { // write code here } module.exports = { operate : operate };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param a int整型 # @param b int整型 # @return int整型一维数组 # class Solution: def operate(self , a: int, b: int) -> List[int]: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ func operate( a int , b int ) []int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 * @return int* returnSize 返回数组行数 */ int* operate(int a, int b, int* returnSize ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param a int整型 # @param b int整型 # @return int整型一维数组 # class Solution def operate(a, b) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ def operate(a: Int,b: Int): Array[Int] = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ fun operate(a: Int,b: Int): IntArray { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ public int[] operate (int a, int b) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ export function operate(a: number, b: number): number[] { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ func operate ( _ a: Int, _ b: Int) -> [Int] { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param a int整型 * @param b int整型 * @return int整型一维数组 */ pub fn operate(&self, a: i32, b: i32) -> Vec
{ // write code here } }
2,2
[4,0,4,1,0]