506.Print a Number Increasing Pyramid
Easy
Given an integer
n, return the n rows of a centered number pyramid — row i has (n − i) leading spaces, followed by the numbers 1 through i.
This borrows the Left Half Pyramid's exact space formula, filled with counting numbers instead of stars. The nested loopsNested LoopsAn outer loop over rows, one inner loop for the leading spaces, another for the numbers. version builds each piece explicitly; the built-in repeat + range/joinBuilt-in Repeat + Range/JoinBuilding the spaces with a repeat and the numbers with a range-and-join, then concatenating the two pieces. version replaces both inner loops with two built-in calls and a concatenation.
Example 1:
Input: n = 3
Output: [" 1"," 1 2","1 2 3"]
Example 2:
Input: n = 1
Output: ["1"]
+ 1 hidden test case run on Submit.
Constraints:
- ●
1 ≤ n ≤ 9
n =
3