Explanation

495.Count the Numbers from 1 to N

Easy
Given a non-negative integer n, return how many numbers there are from 1 to n. The loopCounter LoopWalking i from 1 to n, incrementing a counter once per iteration. version practices the fundamental pattern of counting things with a loop — useful when what's being counted isn't already known in advance. The direct returnDirect ReturnRecognizing that the quantity being counted is already exactly n, with nothing left to compute. version is the lesson this particular problem is really teaching: sometimes the "count" a loop would produce is already sitting in a variable, and the loop is pure, provable overhead.

Example 1:

Input: n = 5

Output: 5

Example 2:

Input: n = 1

Output: 1

Example 3:

Input: n = 0

Output: 0

+ 2 hidden test cases run on Submit.

Constraints:

  • ●0 ≤ n ≤ 1000000

n =

5