Print All Primes up to N
EasyP2Coding
Given an integer n, return all prime numbers p with 1 <= p <= n in increasing order. Return an empty array if there are none.
Example 1
- Input
- n = 10
- Output
- [2,3,5,7]
Example 2
- Input
- n = 1
- Output
- []
Example 3
- Input
- n = 2
- Output
- [2]
Constraints
- 0 <= n <= 10^6
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.