문제
Python Code
def solution(arr, k):
unique_nums = set()
result = []
for num in arr:
if num not in unique_nums:
unique_nums.add(num)
result.append(num)
if len(result) == k:
break
while len(result) < k:
result.append(-1)
return result
Go Code
func solution(arr []int, k int) []int {
uniqueNums := make(map[int]bool)
result := []int{}
for _, num := range arr {
if !uniqueNums[num] {
uniqueNums[num] = true
result = append(result, num)
}
if len(result) == k {
break
}
}
for len(result) < k {
result = append(result, -1)
}
return result
}
결과
문제출처 & 깃허브
programmers
Github