Skip to content

Latest commit

 

History

History
28 lines (22 loc) · 631 Bytes

Question_2540.md

File metadata and controls

28 lines (22 loc) · 631 Bytes

LeetCode Records - Question 2540 Minimum Common Value

Attempt 1: Use a HashSet

class Solution {
    public int getCommon(int[] nums1, int[] nums2) {
        Set<Integer> set = new HashSet<>();
        
        for (int num : nums1) {
            set.add(num);
        }

        int common = Integer.MAX_VALUE;

        for (int num : nums2) {
            if (set.contains(num)) {
                common = Math.min(common, num);
            }
        }

        return common == Integer.MAX_VALUE ? -1 : common;
    }
}
  • Runtime: 14 ms (Beats: 21.29%)
  • Memory: 65.06 MB (Beats: 5.32%)