Java - using hashset
Store all the values in hashset.\n2. Iterate over all the numbers. For positive numbers, check if i\'ts negative counterpart exists. If so, check if it is large
1. Store all the values in hashset.\n2. Iterate over all the numbers. For positive numbers, check if i\'ts negative counterpart exists. If so, check if it is largest value encoutered so far and update the answer accordingly.\n# class Solution {\n    public int findMaxK(int[] nums) {\n        HashSet<Integer> set = new HashSet();\n        \n        for(int num : nums){\n            set.add(num);\n        }\n        \n        int ans = -1;\n        for(int num : nums){\n            if(num>0 && set.contains(-1*num)){\n                ans = Math.max(num, ans);\n            }\n        }\n        \n        return ans;\n    }\n}
[]