Java 8 - 1 line of code using streams


  • 1
    W
    public int[] intersection(int[] nums1, int[] nums2) {
            
           return IntStream.of( nums1 ).boxed().collect(Collectors.toList()).stream().filter( IntStream.of( nums2 ).boxed().collect(Collectors.toList())::contains  ).collect(Collectors.toSet()).stream().mapToInt(u -> u).toArray();
            
        }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.