Skip to content

Commit f97b923

Browse files
refactor 679
1 parent 19352fa commit f97b923

File tree

1 file changed

+4
-25
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+4
-25
lines changed

src/main/java/com/fishercoder/solutions/_679.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,14 @@
22

33
import java.util.stream.IntStream;
44

5-
/**
6-
* 679. 24 Game
7-
*
8-
* You have 4 cards each containing a number from 1 to 9.
9-
* You need to judge whether they could operated through *, /, +, -, (, ) to get the value of 24.
10-
11-
Example 1:
12-
Input: [4, 1, 8, 7]
13-
Output: True
14-
Explanation: (8-4) * (7-1) = 24
15-
16-
Example 2:
17-
Input: [1, 2, 1, 2]
18-
Output: False
19-
20-
Note:
21-
The division operator / represents real division, not integer division. For example, 4 / (1 - 2/3) = 12.
22-
Every operation done is between two numbers.
23-
In particular, we cannot use - as a unary operator. For example, with [1, 1, 1, 1] as input, the expression -1 - 1 - 1 - 1 is not allowed.
24-
You cannot concatenate numbers together. For example, if the input is [1, 2, 1, 2], we cannot write this as 12 + 12.
25-
26-
*/
27-
285
public class _679 {
296
public static class Solution1 {
30-
/**Since there are only 4 cards and only 4 operations, we can iterate through all possible combinations, there's a total of 9216 possibilities:
7+
/**
8+
* Since there are only 4 cards and only 4 operations, we can iterate through all possible combinations, there's a total of 9216 possibilities:
319
* 1. we pick two out of four cards, with order (since order matters for division), 4 * 3 = 12, then pick one of four operations: 12 * 4 = 48;
3210
* 2. then we pick two from these three numbers: 12 * 4 * 3 * 4 * 2 = 1152
33-
* 3. then we pick the remaining two: 1152 * 2 * 4 = 9216 (with order and out of 4 operations)*/
11+
* 3. then we pick the remaining two: 1152 * 2 * 4 = 9216 (with order and out of 4 operations)
12+
*/
3413
public boolean judgePoint24(int[] nums) {
3514
return dfs(IntStream.of(nums).mapToDouble(num -> num).toArray());
3615
}

0 commit comments

Comments
 (0)