☠💀💯 Faster✅💯 Lesser🧠 🎯 C++✅Python3✅Java✅C✅Python✅C#✅💥🔥💫Explained☠💥🔥 Beats 💯
Intuition\n\n\n\nC++ []\nclass Solution {\npublic:\n    int findMaxK(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        int low = 0, high = 
# Intuition\n![0ehh83fsnh811.jpg](https://assets.leetcode.com/users/images/9686e2e9-bde0-4d3d-9b04-cf798bc2b85b_1714614972.0940583.jpeg)\n![Screenshot 2024-05-02 072514.png](https://assets.leetcode.com/users/images/d61d1156-f949-4960-b288-13585cf68727_1714614981.1707056.png)\n![Screenshot 2024-05-02 072549.png](https://assets.leetcode.com/users/images/31f1e039-558d-46b0-8d72-9dccf5d951aa_1714614987.5647128.png)\n```C++ []\nclass Solution {\npublic:\n    int findMaxK(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        int low = 0, high = nums.size() - 1;\n\n        while (low < high) {\n            if ((nums[low] + nums[high]) == 0) {\n                return nums[high];\n            }\n            else if ((nums[low] + nums[high]) < 0)\n                low++;\n            else\n                high--;\n        }\n        return -1;\n    }\n};\n```\n```python3 []\nclass Solution:\n    def findMaxK(self, nums: List[int]) -> int:\n        sm = [0] * 1001\n        maxi = -1\n        for n in nums:\n            idx = n if n > 0 else -n\n            if sm[idx] != n:\n                sm[idx] += n\n            if sm[idx] == 0:\n                maxi = maxi if maxi > idx else idx\n        return maxi\n```\n```C# []\npublic class Solution {\n    public int FindMaxK(int[] nums) {\n        Array.Sort(nums);\n        int j = nums.Length - 1, i = 0;\n        while (i < j) {\n            int a = -1 * nums[j];\n            if (nums[i] == a)\n                return nums[j];\n            else if (nums[i] < a)\n                i++;\n            else\n                j--;\n        }\n        return -1;\n    }\n}\n```\n```Java []\nclass Solution {\n    public int findMaxK(int[] nums) {\n        Arrays.sort(nums);\n        int j = nums.length - 1, i = 0;\n        while (i < j) {\n            int a = -1 * nums[j];\n            if (nums[i] == a)\n                return nums[j];\n            else if (nums[i] < a)\n                i++;\n            else\n                j--;\n        }\n        return -1;\n    }\n}\n```\n```python []\nclass Solution(object):\n    def findMaxK(self, nums):\n        """\n        :type nums: List[int]\n        :rtype: int\n        """\n        k = -1\n        nums_set = set(nums)\n        for n in nums:\n            if n > 0:\n                if n > k and -n in nums_set:\n                    k = n\n\n\n        return k\n```\n```C []\nint cmpfunc(const void* a, const void* b) { \n    return (*(int*)a - *(int*)b);\n    }\nint findMaxK(int* nums, int numsSize) {\n    qsort(nums, numsSize, sizeof(int), cmpfunc);\n    int j = numsSize - 1, i = 0;\n    while (i < j) {\n        int a = -1 * nums[j];\n        if (nums[i] == a)\n            return nums[j];\n        else if (nums[i] < a)\n            i++;\n        else\n            j--;\n    }\n    return -1;\n}\n```\n\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n      O(nlogn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n      O(1)\n# Code\n```\nclass Solution {\npublic:\n    int findMaxK(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        int low = 0, high = nums.size() - 1;\n\n        while (low < high) {\n            if ((nums[low] + nums[high]) == 0) {\n                return nums[high];\n            }\n            else if ((nums[low] + nums[high]) < 0)\n                low++;\n            else\n                high--;\n        }\n        return -1;\n    }\n};\n```
['Array', 'Hash Table', 'Two Pointers', 'C', 'Python', 'C++', 'Java', 'Python3', 'C#']