Skip to content

Practice 24 Game

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#679
LeetCode Problem

24 Game

Problem Statement

Use each of the four given cards exactly once to form an expression equal to 24. You may rearrange the cards and use addition, subtraction, multiplication, division and parentheses. Division is real-valued rather than integer division. Every operator combines two numbers: unary negation is forbidden, and adjacent card values cannot be concatenated into a new number. Return whether a valid expression exists.

Source: 24 Game on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
cards = [4,1,8,7]
Output
true

# Example 2

Input
cards = [1,2,1,2]
Output
false

Constraints

cards.length == 4
1 <= cards[i] <= 9

Related LeetCode Problems

Practice more problems similar to 24 Game.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.