Simple Java O(n) with single For-loop & single HashMap
Solved it by One For-loop and One HashMap\n```\npublic int findPairs(int[] nums, int k) {\n    if(k < 0) return 0;\n    Map map = new HashMap();\n    int ret = 
Solved it by One For-loop and One HashMap\n```\npublic int findPairs(int[] nums, int k) {\n    if(k < 0) return 0;\n    Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();\n    int ret = 0;\n    for(int n : nums){\n        /* if smaller matched value exists */\n        if(map.containsKey(n-k) && !map.get(n-k)){\n            map.put(n-k,true);\n            ret++;\n        }\n        /* if larger matched value exists */\n        if(map.containsKey(n+k) && (!map.containsKey(n) || !map.get(n))){\n            map.put(n, true);\n            ret++;\n        }\n        /* if current value has not yet been added*/\n        if(!map.containsKey(n)){\n            map.put(n, false);\n        }\n    }\n    return ret;\n}\n````
[]