← 返回 google 的题目列表Deduplicate and Sort Log Entries
类型:online_judge
Given a list of log entries logs, where each entry is (timestamp, message):
timestamp is an integer timestamp.
message is a string.
Process the logs as follows:
Entries with the same message are duplicates.
For each distinct message, keep only the entry that appears first in the input list.
Return the retained entries sorted by timestamp in ascending order.
Timestamps may not be in input order, and different entries may have equal timestamps. Break timestamp ties by lexicographic order of the message.
Example 1
Input: [(5, "start"), (2, "ready"), (8, "start"), (4, "done")]
Output: [(2, "ready"), (4, "done"), (5, "start")]
Constraints
0 <= len(logs) <= 2 * 10^5
timestamp is a signed 64-bit integer.
message length is from 1 to 200.
Example
Input
4
5 start
2 ready
8 start
4 done
Output
2 ready
4 done
5 start