Explanation

488.Print Numbers from 1 to N

Easy
Given a non-negative integer n, return the numbers from 1 to n, in increasing order. The for loopFor LoopWalking an index from 1 to n, appending each value as it goes. version is the most literal reading of the problem. The built-in rangeBuilt-in Range GenerationA language feature that produces a contiguous sequence of numbers directly, without the programmer tracking an index. version reaches for whatever range-generation tool a language already provides — still the same O(n) amount of work, just expressed without writing the loop by hand.

Example 1:

Input: n = 5

Output: [1,2,3,4,5]

Example 2:

Input: n = 1

Output: [1]

Example 3:

Input: n = 0

Output: []

+ 2 hidden test cases run on Submit.

Constraints:

  • ●0 ≤ n ≤ 1000

n =

5