java.lang.Object
g0901_1000.s0937_reorder_data_in_log_files.Solution

public class Solution extends Object
937 - Reorder Data in Log Files.<p>Easy</p> <p>You are given an array of <code>logs</code>. Each log is a space-delimited string of words, where the first word is the <strong>identifier</strong>.</p> <p>There are two types of logs:</p> <ul> <li><strong>Letter-logs</strong>: All words (except the identifier) consist of lowercase English letters.</li> <li><strong>Digit-logs</strong>: All words (except the identifier) consist of digits.</li> </ul> <p>Reorder these logs so that:</p> <ol> <li>The <strong>letter-logs</strong> come before all <strong>digit-logs</strong>.</li> <li>The <strong>letter-logs</strong> are sorted lexicographically by their contents. If their contents are the same, then sort them lexicographically by their identifiers.</li> <li>The <strong>digit-logs</strong> maintain their relative ordering.</li> </ol> <p>Return <em>the final order of the logs</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> logs = [&ldquo;dig1 8 1 5 1&rdquo;,&ldquo;let1 art can&rdquo;,&ldquo;dig2 3 6&rdquo;,&ldquo;let2 own kit dig&rdquo;,&ldquo;let3 art zero&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;let1 art can&rdquo;,&ldquo;let3 art zero&rdquo;,&ldquo;let2 own kit dig&rdquo;,&ldquo;dig1 8 1 5 1&rdquo;,&ldquo;dig2 3 6&rdquo;]</p> <p><strong>Explanation:</strong></p> <p>The letter-log contents are all different, so their ordering is &ldquo;art can&rdquo;, &ldquo;art zero&rdquo;, &ldquo;own kit dig&rdquo;.</p> <p>The digit-logs have a relative order of &ldquo;dig1 8 1 5 1&rdquo;, &ldquo;dig2 3 6&rdquo;.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> logs = [&ldquo;a1 9 2 3 1&rdquo;,&ldquo;g1 act car&rdquo;,&ldquo;zo4 4 7&rdquo;,&ldquo;ab1 off key dog&rdquo;,&ldquo;a8 act zoo&rdquo;]</p> <p><strong>Output:</strong> [&ldquo;g1 act car&rdquo;,&ldquo;a8 act zoo&rdquo;,&ldquo;ab1 off key dog&rdquo;,&ldquo;a1 9 2 3 1&rdquo;,&ldquo;zo4 4 7&rdquo;]</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= logs.length <= 100</code></li> <li><code>3 <= logs[i].length <= 100</code></li> <li>All the tokens of <code>logs[i]</code> are separated by a <strong>single</strong> space.</li> <li><code>logs[i]</code> is guaranteed to have an identifier and at least one word after the identifier.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • reorderLogFiles

      public String[] reorderLogFiles(String[] logs)