publicbooleanisStraight(int[] nums){ if (nums==null || nums.length == 0) { returntrue; } Arrays.sort(nums); int joker = 0; for (int i = 0; i < nums.length-1; i++) { if (nums[i] == 0) { joker++; }elseif (nums[i] == nums[i+1]) { returnfalse; } } return nums[4] - joker < 4; }
publicbooleanisStraight2(int[] nums){ if (nums==null || nums.length == 0) { returntrue; } Set<Integer> res = new HashSet<>(); int max = 0, min = 14; for (int num : nums) { if (num == 0) { continue; } max = Math.max(max, num); min = Math.min(min, num); if (res.contains(num)) { returnfalse; } res.add(num); } return max - min < 5; // 最大牌 - 最小牌 < 5 则可构成顺子 }