Description

Suppose that you want to check if an array of length n contains numbers 1 through n only once, without duplicates.
Write a function solution to return true when the numbers 1 through n only appears once, without duplicates, and false otherwise.

Constraints
  • Length of array is less than or equal to 100,000.
  • Each element of array is an integer between 0 and 100,000.

Examples
arr result
[4, 1, 3, 2] true
[4, 1, 3] false

Example #1
When [4, 1, 3, 2] is given as input, an array should contain all numbers 1 through 4 because the length of the array is 4. Since [4, 1, 3, 2] contains all numbers 1 through 4, true should be returned.

Example #2
When [4, 1, 3] is given as input, an array should contain all numbers 1 through 3 because the length of the array is 3. However, [4, 1, 3] contains 4 instead of 2, therefore false should be returned.

Result Stop
내가 제출한 코드가 왜 틀렸는지 프로그래머스 AI에게 물어보세요.
제출 후 채점하기를 눌러 30점 이상인 경우 물어볼 수 있어요.
베타 기간 동안에는 한 문제당 1번만 물어볼 수 있어요.