534.Print a Zero-One Triangle
Easy
Given
n, return n rows of a right triangle filled with alternating 1s and 0s: row i has i values separated by single spaces, odd rows start with 1, even rows start with 0, and values alternate along each row.
The pattern is a parityParityWhether a number is even or odd, usually tested with % 2. exercise in disguise — the value in a cell depends only on whether its row number plus column number is even. The second solution trades that formula for a running bit that flips after every cell.
Example 1:
Input: n = 4
Output: ["1","0 1","1 0 1","0 1 0 1"]
Example 2:
Input: n = 1
Output: ["1"]
+ 4 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ n ≤ 20
n =
4