504.Print a Reverse Number Triangle
Easy
Given an integer
n, return the n rows of an upside-down number triangle — row i counts down from (n − i + 1) to 1.
This mirrors the Reverse Right Half Pyramid's shrinking row lengths, filled with counting-down numbers instead of stars. The nested loopsNested LoopsAn outer loop over rows, an inner loop counting down from len to 1 for each row. version builds each row number by number. The range + joinRange + JoinGenerating the descending range len down to 1 directly, then joining it with spaces. version generates the same descending sequence as a single range-and-join expression.
Example 1:
Input: n = 3
Output: ["3 2 1","2 1","1"]
Example 2:
Input: n = 1
Output: ["1"]
+ 1 hidden test case run on Submit.
Constraints:
- ●
1 ≤ n ≤ 9
n =
3