class Solution { public: int maxSubarrayLength(vector<int>& nums, int k) { int size = nums.size(),resLenth = 0; unordered_map<int,int> numAdded; for(int left = 0,right = 0;right < size;++right){ ++numAdded[nums[right]]; if(numAdded[nums[right]] > k){ while(numAdded[nums[right]] > k) --numAdded[nums[left++]];//没必要值为1就erase,题目的求解和numAdded.size()没有任何关系 } resLenth = max(resLenth,right-left+1); } return resLenth; } };
标签:right,nums,int,resLenth,2958,数组,leetcode,numAdded,size From: https://www.cnblogs.com/uacs2024/p/18597434