Explanation

496.Print a Square Star Pattern

Easy
Given an integer n, return the n rows of an n×n block of stars — every row is a string of n asterisks. The nested loopsNested LoopsAn outer loop over rows, and an inner loop that appends one character at a time to build each row. version builds every row character by character — the direct way to think about a grid: n rows, n columns each. The string repetitionString RepetitionA built-in operation that produces a string of a repeated character directly, without an explicit inner loop. version recognizes that every row here is identical, and hands that repetition off to a built-in — still the same O(n²) total output, just without writing the inner loop by hand.

Example 1:

Input: n = 3

Output: ["***","***","***"]

Example 2:

Input: n = 1

Output: ["*"]

+ 2 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ n ≤ 20

n =

3