[알고리즘] permcheck, counting element
https://codility.com/media/train/2-CountingElements.pdf
- PermCheck Check whether array A is a permutation.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
# 비어있지 않은 배열 A는 N개의 정수로 이뤄져있다.
# perm = 1~N 까지 연속적으로 한번씩 쓰인 순열이다.
# 예를 들어, A의 길이가 4이면 요소들은 1~4까지 쓰였다. 이 경우 perm이다.
# len(A) == max(A), len(set(A)) == len(A)
# A[0] = 4
# A[1] = 1
# A[2] = 3
# A[3] = 2
# 반면, 다음은 아니다.
# A[0] = 4
# A[1] = 1
# A[2] = 3
# goal: 배열A가 perm인지 판단하고 맞으면 1, 아니면 0 리턴.
def solution(A):
if len(A) == max(A) and len(set(A)) == len(A):
return 1
else:
return 0
알고리즘 #permcheck #counting
이 기사는 저작권자의 CC BY 4.0 라이센스를 따릅니다.
