679. 24 Game Hard

@problem@discussion
#Array#Math#Backtracking



1/**
2 * [679] 24 Game
3 *
4 * You are given an integer array cards of length 4. You have four cards, each containing a number in the range [1, 9]. You should arrange the numbers on these cards in a mathematical expression using the operators ['+', '-', '*', '/'] and the parentheses '(' and ')' to get the value 24.
5 * You are restricted with the following rules:
6 * 
7 * 	The division operator '/' represents real division, not integer division.
8 * 	
9 * 		For example, 4 / (1 - 2 / 3) = 4 / (1 / 3) = 12.
10 * 	
11 * 	
12 * 	Every operation done is between two numbers. In particular, we cannot use '-' as a unary operator.
13 * 	
14 * 		For example, if cards = [1, 1, 1, 1], the expression "-1 - 1 - 1 - 1" is not allowed.
15 * 	
16 * 	
17 * 	You cannot concatenate numbers together
18 * 	
19 * 		For example, if cards = [1, 2, 1, 2], the expression "12 + 12" is not valid.
20 * 	
21 * 	
22 * 
23 * Return true if you can get such expression that evaluates to 24, and false otherwise.
24 *  
25 * Example 1:
26 * 
27 * Input: cards = [4,1,8,7]
28 * Output: true
29 * Explanation: (8-4) * (7-1) = 24
30 * 
31 * Example 2:
32 * 
33 * Input: cards = [1,2,1,2]
34 * Output: false
35 * 
36 *  
37 * Constraints:
38 * 
39 * 	cards.length == 4
40 * 	1 <= cards[i] <= 9
41 * 
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/24-game/
46// discuss: https://leetcode.com/problems/24-game/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51    pub fn judge_point24(cards: Vec<i32>) -> bool {
52        false
53    }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60    use super::*;
61
62    #[test]
63    fn test_679() {
64    }
65}
66


Back
© 2025 bowen.ge All Rights Reserved.