← 返回 snapchat 的题目列表Can a target string be formed using double-sided letter cards (each card used at most once)?
类型:online_judge
You are given cards, where each card has two sides and each side contains one lowercase English letter, e.g., cards = [["a","b"], ["c","d"]].
Rules:
Each card can be used at most once.
When a card is used, you may pick either the front or the back letter.
Given a target string target, determine whether you can form target such that each character is supplied by a distinct card.
Example
cards = [["a","b"], ["c","d"]]
target = "ac" -> true
target = "ab" -> false
Assumed constraints
1 <= len(cards) <= 2*10^5
1 <= len(target) <= len(cards)
Provide an algorithm that scales to large inputs.
Example
Input
cards=[["a","b"],["c","d"]], target="ac"
Output
true