Beats 100% in memory, time, C++, easy to understand
\n\n# Approach\nSort the vector and traverse every element from opposite side. If nums[i] is the answer, then the sum excluding nums[i] should be 1) even 2) (su
\n\n# Approach\nSort the vector and traverse every element from opposite side. If nums[i] is the answer, then the sum excluding nums[i] should be 1) even 2) (sum-num[i])/2 should be present in the vector and the index shouldn\'t be equal to i. If all these conditions are met, then the answer is nums[i].\n\n# Complexity\n- Time complexity: O(nlogn)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int getLargestOutlier(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        int sum = accumulate(nums.begin(), nums.end(), 0);\n        int n = nums.size();\n        for(int i = n-1;i>=0;i--) {\n            sum -= nums[i];\n            if(sum%2 == 0) {\n                int ind = lower_bound(nums.begin(), nums.end(), sum/2) - nums.begin();\n                if(ind < n && ind != i && nums[ind] == sum/2) {\n                    return nums[i];\n                }\n            }\n            sum += nums[i];\n        }\n        return -1;\n    }\n};\n```
['C++']