Untitled

Anonymous
Plain Text
10/08/2025 5:25 PM
518 B
18
Indexable
Never
public static boolean pairSum(int[] arr, int target) {
        HashMap<Integer, Integer> hm = new HashMap<>();
        for (int i : arr) {
            if (hm.containsKey(i)) {
                hm.put(i, hm.get(i) + 1);
            } else {
                hm.put(i, 1);
            }
        }

        for (int i = 0; i < arr.length; i++) {
            int y = target - arr[i];
            if (hm.containsKey(y) && hm.get(arr[i]) > 1) {
                return true;
            }
        }

        return false;
    }
Editor is loading...
Leave a Comment