535.Print a Right Pascal's Triangle Star Pattern
Easy
Given
n, return 2n − 1 left-aligned rows of stars whose lengths go 1, 2, …, n and then back down to 1 — an arrow pointing to the right. (The name comes from its outline, not from Pascal's number triangle.)
It is a Right Half Pyramid followed by its reverse, sharing the widest row. The first solution writes the two halves with two loops; the second uses the distance from the middleDistance from the MiddleFor row r, |n − 1 − r| counts how many rows it is away from the widest row; the width shrinks by one per step. to give every row its width in a single loop.
Example 1:
Input: n = 3
Output: ["*","**","***","**","*"]
Example 2:
Input: n = 1
Output: ["*"]
+ 4 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ n ≤ 20
n =
3