题解 | #扑克牌顺子#
扑克牌顺子
https://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4
import java.util.Arrays; public class Solution { public boolean IsContinuous(int [] numbers) { //先排序 1. A为1,J为11,Q为12,K为13 Arrays.sort(numbers); //如果有4个0 直接返回true if (numbers[3] == 0) { return true; } // int k = numbers[4] - numbers[3]; if (k == 0) { return false; } //如果3个0 00015 00026 00013 00012 00014 if (numbers[2] == 0 && k <= 4 && k >= 1) { return true; } //如果2个0 00123 00134 00145 00234 [1,3,0,7,0] 00137 if (numbers[1] == 0 && numbers[4] - numbers[2] >= 2 && numbers[4] - numbers[2] <= 4) { return true; } //如果1个0 01234 01345 01245 01345 if (numbers[0] == 0 && (numbers[4] - numbers[1] == 3 || numbers[4] - numbers[1] == 4)) { return true; } //没有0 12345 if (numbers[4] - numbers[0] == 4) { return true; } /**for(int i: numbers){ System.out.println(i); }*/ return false; } }