What is shortest in code terms way for given N to output strings "1", "1 2"... "1 2 ... N"?

101 Views Asked by At

What is shortest in code terms way for given N (int) to output List<strings> out; containing strings "1", "1 2"... "1 2 ... N"? For N == 3 out would contain "1"; "1 2"; "1 2 3"

1

There are 1 best solutions below

1
On BEST ANSWER
Enumerable.Range(1, n)
          .Select(i => String.Join(" ", Enumerable.Range(1, i)))
          .ToList();

For n = 3 produces:

[
  "1",
  "1 2",
  "1 2 3"
]