java:
每日一题 学习一下
class Solution {
public boolean isNStraightHand(int[] hand, int groupSize) {
int n = hand.length;
if (hand == null || n % groupSize != 0) {
return false;
}
if (groupSize == 1) {
return true;
}
Arrays.sort(hand);
Queue queue = new linkedList<>();
for (int i = 0; i < n; i++) {
if (queue.isEmpty() || queue.peek()[0] == hand[i]){
queue.offer(new int[]{hand[i], 1});
} else if (queue.peek()[0] + 1 == hand[i]) {
int[] cur =queue.poll();
cur[0] = hand[i];
if (++cur[1] != groupSize) {
queue.offer(cur);
}
} else {
return false;
}
}
return queue.isEmpty();
}
}



