937. Reorder Data in Log Files Medium
1/**
2 * [937] Reorder Data in Log Files
3 *
4 * You are given an array of logs. Each log is a space-delimited string of words, where the first word is the identifier.
5 * There are two types of logs:
6 *
7 * Letter-logs: All words (except the identifier) consist of lowercase English letters.
8 * Digit-logs: All words (except the identifier) consist of digits.
9 *
10 * Reorder these logs so that:
11 * <ol>
12 * The letter-logs come before all digit-logs.
13 * The letter-logs are sorted lexicographically by their contents. If their contents are the same, then sort them lexicographically by their identifiers.
14 * The digit-logs maintain their relative ordering.
15 * </ol>
16 * Return the final order of the logs.
17 *
18 * Example 1:
19 *
20 * Input: logs = ["dig1 8 1 5 1","let1 art can","dig2 3 6","let2 own kit dig","let3 art zero"]
21 * Output: ["let1 art can","let3 art zero","let2 own kit dig","dig1 8 1 5 1","dig2 3 6"]
22 * Explanation:
23 * The letter-log contents are all different, so their ordering is "art can", "art zero", "own kit dig".
24 * The digit-logs have a relative order of "dig1 8 1 5 1", "dig2 3 6".
25 *
26 * Example 2:
27 *
28 * Input: logs = ["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"]
29 * Output: ["g1 act car","a8 act zoo","ab1 off key dog","a1 9 2 3 1","zo4 4 7"]
30 *
31 *
32 * Constraints:
33 *
34 * 1 <= logs.length <= 100
35 * 3 <= logs[i].length <= 100
36 * All the tokens of logs[i] are separated by a single space.
37 * logs[i] is guaranteed to have an identifier and at least one word after the identifier.
38 *
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/reorder-data-in-log-files/
43// discuss: https://leetcode.com/problems/reorder-data-in-log-files/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48 pub fn reorder_log_files(logs: Vec<String>) -> Vec<String> {
49 vec![]
50 }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58
59 #[test]
60 fn test_937() {
61 }
62}
63
Back
© 2025 bowen.ge All Rights Reserved.