← 返回 google 的题目列表Keep the Most Recent Log for Each Message
类型:online_judge
Given a list of log entries logs, where each entry is (timestamp, message), entries with the same message are duplicates.
Unlike the first-occurrence version, retain only the entry with the greatest timestamp for each message. Return the final entries in ascending timestamp order. Break ties between retained entries by lexicographic message order.
If the same message occurs multiple times at its maximum timestamp, retaining any one is sufficient because the resulting entries are identical.
Example
Input: [(5, "start"), (2, "ready"), (8, "start"), (4, "done")]
Output: [(2, "ready"), (4, "done"), (8, "start")]
Constraints
0 <= len(logs) <= 2 * 10^5
timestamp is a signed 64-bit integer.
Example
Input
4
5 start
2 ready
8 start
4 done
Output
2 ready
4 done
8 start