505.Print a Number Changing Pyramid
Easy
Given an integer
n, return the n rows of a "changing" number pyramid — row i counts up from 1 to i, then back down to 1.
The nested loopsNested LoopsAn ascending inner loop (1 to i) followed immediately by a descending one (i-1 down to 1), each with their own space-handling. version writes the direction change as two separate loops back to back. The two rangesBuild Two Ranges, Then JoinGenerating the ascending and descending sequences as two separate lists, concatenating them, then joining the combined result once. version builds the same two pieces as data first, concatenates them, and joins ONLY once — so there's no risk of mismatched space logic where the two directions meet.
Example 1:
Input: n = 3
Output: ["1","1 2 1","1 2 3 2 1"]
Example 2:
Input: n = 1
Output: ["1"]
+ 1 hidden test case run on Submit.
Constraints:
- ●
1 ≤ n ≤ 9
n =
3