We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
class Solution { public: int maxOperations(vector<int>& nums, int k) { unordered_map<int, int> numCount; int operations = 0; for (int num : nums) { int complement = k - num; if (numCount[complement] > 0) { operations++; numCount[complement]--; } else { numCount[num]++; } } return operations; } };
class Solution { public: int maxOperations(vector<int>& nums, int k) { int result = 0; int left = 0; int right = nums.size() - 1; sort(nums.begin(), nums.end()); while (left < right) { if (nums[left] + nums[right] == k) { result++; left++; right--; } else if (nums[left] + nums[right] > k) { right--; } else if (nums[left] + nums[right] < k) { left++; } } return result; } };
The text was updated successfully, but these errors were encountered:
fkdl0048
No branches or pull requests
The text was updated successfully, but these errors were encountered: