/**
 * Given two lists of integers nums1 and nums2,
 * write a function that returns their intersection.
 * The intersection is a list containing distinct elements present in both nums1 and nums2.
 *
 * Complete the given function intersection, which takes in two arguments:
 * - nums1: a list of integers
 * - nums2: a list of integers
 *
 * The function should return a list of distinct numbers that appear in both nums1 and nums2.
 *
 * Your task is to complete the function using a for loop with a list comprehension.
 *
 * Example:
 * Input:
 * nums1 = [1,2,2,1]
 * nums2 = [2,2]
 * Output:
 * [2]
 *
 * Note:
 * - The intersection should not contain duplicate elements.
 * - The input lists can be of different lengths.
 * - The order of the elements in the output list does not matter.
 */
fun intersection(nums1: List<Int>, nums2: List<Int>): List<Int> {

    val intersectionList = nums1.filter { it in nums2 }.distinct()
    return intersectionList
}
/**
 * Given two lists of integers nums1 and nums2,
 * write a function that returns their intersection.
 * The intersection is a list containing distinct elements present in both nums1 and nums2.
 *
 * Complete the given function intersection, which takes in two arguments:
 * - nums1: a list of integers
 * - nums2: a list of integers
 *
 * The function should return a list of distinct numbers that appear in both nums1 and nums2.
 *
 * Your task is to complete the function using a for loop with a list comprehension.
 *
 * Example:
 * Input:
 * nums1 = [1,2,2,1]
 * nums2 = [2,2]
 * Output:
 * [2]
 *
 * Note:
 * - The intersection should not contain duplicate elements.
 * - The input lists can be of different lengths.
 * - The order of the elements in the output list does not matter.
 */
fun intersection(nums1: List<Int>, nums2: List<Int>): List<Int> {
/**
 * Given two lists of integers nums1 and nums2,
 * write a function that returns their intersection.
 * The intersection is a list containing distinct elements present in both nums1 and nums2.
 *
 * Complete the given function intersection, which takes in two arguments:
 * - nums1: a list of integers
 * - nums2: a list of integers
 *
 * The function should return a list of distinct numbers that appear in both nums1 and nums2.
 *
 * Your task is to complete the function using a for loop with a list comprehension.
 *
 * Example:
 * Input:
 * nums1 = [1,2,2,1]
 * nums2 = [2,2]
 * Output:
 * [2]
 *
 * Note:
 * - The intersection should not contain duplicate elements.
 * - The input lists can be of different lengths.
 * - The order of the elements in the output list does not matter.
 */
fun intersection(nums1: List<Int>, nums2: List<Int>): List<Int> {

    val intersectionList = nums1.filter { it in nums2 }.distinct()
    return intersectionList
}