标签:efault ash http can bool lse default get alt
class Solution {
public boolean canDivideIntoSubsequences(int[] nums, int K) {
int now = 0;
int m = 0;
for (int i = 0; i < nums.length; i++) {
now++;
if (i == nums.length - 1 || nums[i] != nums[i + 1]) { //i==nums.length-1 使得m最小为1
m = Math.max(now, m);
now = 0;
}
}
return (nums.length / m) >= K;
}
}
这道题也是统计有多少个相同的数 然后划分
class Solution {
public boolean canDivideIntoSubsequences(int[] nums, int K) {
Map<Integer, Integer> cnt = new HashMap<>();
int mx = 0;
for (int i = 0; i < nums.length; i++) {
cnt.put(nums[i], cnt.getOrDefault(nums[i], 0) + 1);
mx = Math.max(mx, cnt.get(nums[i]));
}
if ((long) mx * K > nums.length) return false;
return true;
}
}
标签:efault ash http can bool lse default get alt
原文地址:https://www.cnblogs.com/cznczai/p/11183078.html