← 返回 scale.ai 的题目列表Card Game Rule Validation
类型:online_judge
Description
Write a function is_valid_hand(hand: List[str], rules: List[List[str]]) -> bool to determine whether a given hand of cards matches specified card rules.
hand: A list of strings representing a hand of cards, where each card is represented by two characters, the first for rank (2-10, J, Q, K, A) and the second for suit (S, H, D, C).
rules: A list of strings, each representing a rule based on a combination of card ranks, e.g., ["2S", "3S", "4S", "5S", "6S"] for a straight.
The function returns a boolean, True if hand satisfies any of the rules, otherwise False.
Example
Input: hand = ["2S", "3S", "4S", "5S", "6S"], rules = [["2S", "3S", "4S", "5S", "6S"], ["9C", "10C", "JC", "QC", "KC"]]
Output: True
Constraints
1 <= len(hand) <= 7
Each rule should be of the same length as the hand and must be non-empty.
Follow-up Question
How would you modify the code to allow for wildcard logic, where some cards in the hand can become any value?
Example
Input
['2S', '3S', '4S', '5S', '6S'] [[['2S', '3S', '4S', '5S', '6S'], ['9C', '10C', 'JC', 'QC', 'KC']]]