DDSA
Advertisement

Two Sum - Pair with Given Sum

Two Sum - Pair with Given Sum.java
Java

class Solution {
    boolean twoSum(int arr[], int target) {
        HashMap<Integer, Integer> mm = new HashMap<>();
        for (int x : arr) {
            if (mm.get(target - x) != null)
                return true;
            mm.put(x, 1);
        }
        return false;
    }
}
Advertisement
Was this solution helpful?