Explanation

502.Print a Number Square Pattern

Easy
Given an integer n, return the n rows of a number square — row i is the number i, repeated n times and separated by single spaces. The nested loopsNested LoopsAn outer loop over rows, an inner loop appending the row number n times, with spaces between repeats. version builds each row number by number. The join/repeatBuild with Join / RepeatDescribing the row directly as "the string i, repeated n times, joined by spaces" — a single expression in most languages. version says exactly that in one expression, skipping the inner loop in every language with that built-in available.

Example 1:

Input: n = 3

Output: ["1 1 1","2 2 2","3 3 3"]

Example 2:

Input: n = 1

Output: ["1"]

+ 1 hidden test case run on Submit.

Constraints:

  • ●1 ≤ n ≤ 9

n =

3