508.Print a Continuously Increasing Number Triangle
Easy
Given an integer
n, return the n rows of Floyd's Triangle — a continuously counting-up sequence where row i holds the next i numbers, and the count never resets between rows.
This is easy to confuse with the Increasing Number Triangle, which restarts at 1 every row — here, row 2 picks up exactly where row 1 left off. The shared counterShared CounterA counter variable declared OUTSIDE the row loop, so it keeps climbing across every row instead of resetting. version makes that explicit by carrying one counter variable through the whole computation. The running range sliceRunning Range SliceComputing each row's starting number directly from the triangular-number formula i(i-1)/2 + 1, so any single row can be produced without having computed the rows before it. version instead computes, for any row, exactly where in the overall count it should start — no running state required at all.
Example 1:
Input: n = 3
Output: ["1","2 3","4 5 6"]
Example 2:
Input: n = 1
Output: ["1"]
+ 1 hidden test case run on Submit.
Constraints:
- ●
1 ≤ n ≤ 9
n =
3