https://app.codility.com/programmers/lessons/15-caterpillar_method/abs_distinct/

 

AbsDistinct coding task - Learn to Code - Codility

Compute number of distinct absolute values of sorted array elements.

app.codility.com

 

 

  • 내림차순 배열 A이 주어질 때
  • 절대 값으로 고유한 값들의 개수 구하기
  • O(N) or O(N*log(N))

 

def solution(A):
    res = []
    for i in A:
        res.append(abs(i))
    res = list(set(res))
    return len(res)

+ Recent posts