Factorial of a Number
Given a non-negative integer n, compute and return its factorial. The factorial of n, written n!, is the product of all positive integers from 1 up to and…
Given a non-negative integer `n`, compute and return its factorial. The factorial of `n`, written `n!`, is the product of all positive integers from `1` up to and including `n`. By convention, `0!` equals `1`.
- `0 <= n <= 12` - The result fits within a 32-bit signed integer for all valid inputs.
Example 1: input n = 6; output 720. 6! = 6 × 5 × 4 × 3 × 2 × 1 = 720.
Example 2: input n = 0; output 1. 0! is defined as 1 by convention — the empty product.
Example 3: input n = 4; output 24. 4! = 4 × 3 × 2 × 1 = 24.
Category: Math. Topic: math. Difficulty: Easy. Patterns: math, recursion.