[LeetCode] 2215. Find the Difference of Two Arrays(Kotlin)

0

LeetCode

목록 보기
55/58
post-thumbnail

[LeetCode]

[LeetCode] 2215. Find the Difference of Two Arrays(Kotlin)

풀이

class Solution {
    fun findDifference(nums1: IntArray, nums2: IntArray): List<List<Int>> {
        var set1 = nums1.toSet()
        var set2 = nums2.toSet()

        var answer1 = arrayOf<Int>()
        for(i in set1){
            if(!set2.contains(i)) answer1 += i
        }
        var answer2 = arrayOf<Int>()
        for(i in set2){
            if(!set1.contains(i)) answer2 += i
        }

        return listOf(answer1.toList(), answer2.toList())
    }
}
profile
Be able to be vulnerable, in search of truth

0개의 댓글