SuperhumanOA #1
Lost Messages
估计简单评测数据准备中,可先阅读题面
A message is represented as a string of space-delimited words. You are given two strings:
sent: the original messagereceived: the message that was recovered after transmission Some words may be missing fromreceived. It is guaranteed that all words inreceivedappear in the same relative order as they do insent. Return all words that appear insentbut do not appear inreceived, preserving their original order. Function Description Complete the functionlostFragmentsin the editor below.lostFragmentshas the following parameters:String sent: the original message that was sentString received: the recovered message after transmission ReturnsString[]: the words fromsentthat are missing fromreceived, in the order they appear insent
Constraints
sentandreceivedcontain only lowercase or uppercase English letters and spaces.- Words are separated by single spaces.
1 ≤ received.length() < sent.length() ≤ 10⁵- The length of any individual word in
sentorreceivedis at most15. receivedis guaranteed to be a subsequence ofsentat the word level.
Example 1
Input:
sent = "I am a programmer"
received = "I programmer"
Output:
["am", "a"]
Explanation:
The words "am" and "a" appear in sent but are missing from received, so they are returned in order.
Example 2
Input:
sent = "we love coding daily"
received = "we coding"
Output:
["love", "daily"]
Explanation:
The recovered message keeps "we" and "coding" in order, so the missing words are "love" and "daily".
Example 3
Input:
sent = "alpha beta gamma delta"
received = "alpha delta"
Output:
["beta", "gamma"]
Explanation: The recovered message is a subsequence of the sent message. The missing words between the matched endpoints are returned.