题解 | #扑克牌顺子#
扑克牌顺子
https://www.nowcoder.com/practice/762836f4d43d43ca9deb273b3de8e1f4
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param numbers int整型一维数组 * @return bool布尔型 */ public boolean IsContinuous (int[] numbers) { // write code here // compare min and max , differ must <5, no same number for (int i = 0; i < numbers.length - 1; i++) { for (int j = i + 1; j < numbers.length; j++) { if (numbers[i] == numbers[j] && numbers[i] != 0) { return false; } } } int min = 13; int max = 0; for (int i : numbers) { if (i != 0) { min = Math.min(min, i); } max = Math.max(max, i); } if (max - min < 5) { return true; } else { return false; } } }
大胆预测顺子差值不能超过4