package com.patience.interview.algorithms;
import java.util.*;
public class SolveQ2 {
public static void main(String[] args) {
int [] nums = new int[]{2,3,4,10,5,14};
List<Integer> black = new ArrayList<>();
List<Integer> red = new ArrayList<>();
List<Integer> flower = new ArrayList<>();
List<Integer> chip = new ArrayList<>();
for (int i = 0; i < nums.length; i++) {
if(nums[i] <= 13)
black.add(nums[i]);
else if(nums[i] <= 26)
red.add(nums[i]);
else if(nums[i] <= 39)
flower.add(nums[i]);
else if(nums[i] <= 52)
chip.add(nums[i]);
}
boolean one = check(black);
if(!one)
one = check(red);
if(!one)
one = check(flower);
if(!one)
one = check(chip);
System.out.printf("同花顺:%s\n",one);
}
public static boolean check(List<Integer> set){
if(set.size() == 13) return true;
Collections.sort(set);
for (int i = 0; i < set.size(); i++) {
boolean one = set.get(i) % 13 != 0;
boolean two = (set.get(i) + 1) % 13 != 0;
if(one && two ){
boolean $3 = i + 1 <= set.size() - 1;
boolean $4 = i + 2 <= set.size() - 1;
if($3 && $4){
boolean $1 = (set.get(i) + 1) == set.get(i + 1);
boolean $2 = (set.get(i) + 2 == set.get(i + 2));
if($1 && $2)
return true;
}
}
}
return false;
}
}
|