How does the recursion here work?

后端 未结 9 1137
悲&欢浪女
悲&欢浪女 2021-01-04 12:18

Code 1:

public static int fibonacci (int n){ 
    if (n == 0 || n == 1) { 
        return 1; 
    } else { 
        return fibonacci (n-1) + fibonacci (n-2)         


        
9条回答
  •  借酒劲吻你
    2021-01-04 12:48

    Try to draw an illustration yourself, you will eventually see how it works. Just be clear that when a function call is made, it will fetch its return value first. Simple.

提交回复
热议问题