← 返回 snapchat 的题目列表Check if List is a Permutation
类型:online_judge
Given an integer list of length n + 1, determine whether the list is a permutation of numbers from 0 to n. A permutation is defined as having no duplicate numbers and containing all integers from 0 to n.
Implement a function to solve this problem with the following requirements:
Input is an integer list of length n + 1.
Return true if the list is a permutation, otherwise return false.
Example
Input:
[0, 1, 2, 3]
Output:
False
Input:
[0, 2, 3, 1]
Output:
True
Constraints
The integers in the list are within the range [0, n].
Solve the problem in O(n) time complexity.
Try to optimize space complexity to O(1).
Example
Input
[0, 1, 2, 3]