글 작성자: 이지원🌩️

Set을 활용한 문제

문제

https://www.acmicpc.net/problem/1822

내가 작성한 코드

Swift

let n = readLine()!.split(separator: " ").map { Int(String($0))! }
let a = readLine()!.split(separator: " ").map { Int(String($0))! }
let b = readLine()!.split(separator: " ").map { Int(String($0))! }
let ans = Set(a).subtracting(Set(b)).sorted()
print(ans.count)
print(ans.map { String($0) }.joined(separator: " "))
반응형

댓글

댓글을 사용할 수 없습니다.