| 22 | |
| 23 | // O(1) |
| 24 | public static int test(int apple) { |
| 25 | if(apple < 0) { |
| 26 | return -1; |
| 27 | } |
| 28 | if(apple == 0) { |
| 29 | return 0; |
| 30 | } |
| 31 | if(apple < 18) { |
| 32 | if(apple == 6 || apple == 8) { |
| 33 | return 1; |
| 34 | }else if(apple == 12 || apple == 14 || apple == 16) { |
| 35 | return 2; |
| 36 | }else { |
| 37 | return -1; |
| 38 | } |
| 39 | } |
| 40 | // apple >= 18 |
| 41 | // apple 第几组? |
| 42 | // (apple - 18) / 8 |
| 43 | // 18 ~ 25 0组 奇数 -1 偶数 3 |
| 44 | // 26 ~ 33 1组 奇数 -1 偶数 4 |
| 45 | // 34 ~ 41 2组 奇数 -1 偶数 5 |
| 46 | // X >= 18 -> X属于i组, X是奇数 -1 偶数 i + 3 |
| 47 | return apple % 2 == 0 ? ((apple - 18) / 8 + 3) : -1; |
| 48 | } |
| 49 | |
| 50 | public static int minBagAwesome(int apple) { |
| 51 | if (apple < 0 || (apple & 1) != 0) { |