import java.util.*;
public class Solution {
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param numbers int整型一维数组
* @return bool布尔型
*/
public boolean IsContinuous (int[] numbers) {
// write code here
// 组成顺子的条件:顺子不能有重复牌,顺子的最大值和最小值差不能大于4
HashMap<Integer,Integer> hashmap = new HashMap<>();
int max = 0, min = 13;
for(int i = 0;i<numbers.length;i++){
if(numbers[i] != 0){
// 如果有重复牌,则表示不能组成顺子
if(hashmap.containsKey(numbers[i])){
return false;
}
// 添加新牌
hashmap.put(numbers[i],i);
// 更新牌堆里最大值和最小值
if(numbers[i] > max){
max = numbers[i];
}
if(numbers[i] < min){
min = numbers[i];
}
}
}
if(max - min > 4){
return false;
}else{
return true;
}
}
}