第二十七天
美化数组的最少删除数
2216. 美化数组的最少删除数 - 力扣(LeetCode)
class Solution {
public:int minDeletion(vector<int>& nums) {int len = nums.size();if(len == 0) return 0;int res = 0,cur = 0;for(int i = 1;i < len;i++){if(nums[i] == nums [cur]) res++;else cur = ++i;}if((len - res) % 2 !=0) res++; return res;}
};
class Solution {public int minDeletion(int[] nums) {int len = nums.length;int res = 0,cur = 0;for(int i = 1; i < len ; i++){if(nums[cur] == nums[i]) res++;else cur = ++i;}if((len - res) %2 != 0) res++;return res;}
}