没有预期的结果值编译器错误的结果计数

huangapple go评论71阅读模式
英文:

no result values expectedcompilerWrongResultCount

问题

我有这两个函数

func fib_memo(n int) {
    memo := make([]int, n+1)
    return fib_2(n, memo)
}

func fib_2(n int, memo []int) int {
    result := 0
    if &memo[n] != nil {
        return memo[n]
    }
    if n == 1 || n == 2 {
        result = 1
    } else {
        result = fib_2(n-1, memo) + fib_2(n-2, memo)
        memo[n] = result
    }
    return result
}

但是第一个函数给我一个编译错误,我不知道为什么,请帮忙看看:no result values expectedcompilerWrongResultCount

英文:

I have this two functions

func fib_memo(n int) {
	memo := make([]int, n+1)
	return fib_2(n, memo)
}
func fib_2(n int, memo []int) int {
	result := 0
	if &memo[n] != nil {
		return memo[n]
	}
	if n == 1 || n == 2 {
		result = 1
	} else {
		result = fib_2(n-1, memo) + fib_2(n-2, memo)
		memo[n] = result
	}
	return result
}

But the first in giving me a compiler error i don't no why please help : no result values expectedcompilerWrongResultCount

答案1

得分: -1

func fib_memo(n int) (result int) {
memo := make([]int, n+1)
return fib_2(n, memo)
}

英文:
func fib_memo(n int) (result int) {
	memo := make([]int, n+1)
	return fib_2(n, memo)
}

huangapple
  • 本文由 发表于 2022年2月9日 19:35:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/71048869.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定