-5

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"

DuckQueen
  • 772
  • 10
  • 62
  • 134

1 Answers1

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

For n = 3 produces:

[
  "1",
  "1 2",
  "1 2 3"
]
Sergey Berezovskiy
  • 232,247
  • 41
  • 429
  • 459