Home > Back-end >  Return back problem
Return back problem

Time:11-24

Return. Return 2 is to return the result of 2 times, 1 why

CodePudding user response:

That's what you need is to see, such as
looking forward to what kind of resultsReturn is when n is 1, 2 factorial result to 2, namely 1!=2
Return 1 is when n is 1, factorial result is 1, which is 1.=1
If your need is 2 times for n factorial, then return to 2
If your demand is n factorial, then return 1

CodePudding user response:

According to the principle of recursive, return 2 and return 1 is 2 times of problem, because, after returning to 2 recursive implementation by half,
The final execution is 2 x 2 x 3... X 10
Return 1 is executed: 1 * 2 * 3... * 10

CodePudding user response:

reference 1st floor qybao response:
that's what you need is to see, such as
looking forward to what kind of resultsReturn is when n is 1, 2 factorial result to 2, namely 1!=2
Return 1 is when n is 1, factorial result is 1, which is 1.=1
If your need is 2 times for n factorial, then return to 2
If your demand is n factorial, then return 1

Oh, thank you oh, I see

CodePudding user response:

reference 2 building self-confidence boy reply:
, according to the principle of recursive return 2 and return 1 is 2 times the problem, because, after returning to 2 recursive implementation by half,
The final execution is 2 x 2 x 3... X 10
Return 1 is executed: 1 * 2 * 3... * 10

Oh, yes, this is a recursive, I understand, thank you
  • Related