题解 | #扑克牌顺子#
扑克牌顺子
http://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4
public class Solution {
public boolean IsContinuous(int [] numbers) {
int len = numbers.length;
if(len<5) return false;
int[] cups = new int[14];
//这里一共13种数字,所以开13个桶来装数字,
//对应下标装对应数字,数字几就装在几号桶,0号里面可能有多个0;
for(int i=0;i<len;i++){
cups[numbers[i]]++;
}
//从1开始到9,每次步长是5,
//cups[i+j] == 0用于判断每次5个连续数字中有几个空缺的数字
for(int i=1;i<9;i++){
int count =0;
for(int j=0;j<5;j++){
if(cups[i+j] == 0)
count++;
}
//如果万能0的个数大于等于空缺个数,或者没有空缺,则是顺子
if(cups[0]>=count || count == 0)
return true;
}
return false;
}
} 
OPPO公司福利 1147人发布