java.lang.Object
g2701_2800.s2788_split_strings_by_separator.Solution

public class Solution extends Object
2788 - Split Strings by Separator.<p>Easy</p> <p>Given an array of strings <code>words</code> and a character <code>separator</code>, <strong>split</strong> each string in <code>words</code> by <code>separator</code>.</p> <p>Return <em>an array of strings containing the new strings formed after the splits, <strong>excluding empty strings</strong>.</em></p> <p><strong>Notes</strong></p> <ul> <li><code>separator</code> is used to determine where the split should occur, but it is not included as part of the resulting strings.</li> <li>A split may result in more than two strings.</li> <li>The resulting strings must maintain the same order as they were initially given.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> words = [&ldquo;one.two.three&rdquo;,&ldquo;four.five&rdquo;,&ldquo;six&rdquo;], separator = &ldquo;.&rdquo;</p> <p><strong>Output:</strong> [&ldquo;one&rdquo;,&ldquo;two&rdquo;,&ldquo;three&rdquo;,&ldquo;four&rdquo;,&ldquo;five&rdquo;,&ldquo;six&rdquo;]</p> <p><strong>Explanation:</strong></p> <p>In this example we split as follows: &ldquo;one.two.three&rdquo; splits into</p> <p>&ldquo;one&rdquo;, &ldquo;two&rdquo;, &ldquo;three&rdquo; &ldquo;four.five&rdquo; splits into</p> <p>&ldquo;four&rdquo;, &ldquo;five&rdquo; &ldquo;six&rdquo; splits into &ldquo;six&rdquo;</p> <p>Hence, the resulting array is [&ldquo;one&rdquo;,&ldquo;two&rdquo;,&ldquo;three&rdquo;,&ldquo;four&rdquo;,&ldquo;five&rdquo;,&ldquo;six&rdquo;].</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> words = [&ldquo;$easy$&rdquo;,&ldquo;$problem$&rdquo;], separator = &ldquo;$&rdquo;</p> <p><strong>Output:</strong> [&ldquo;easy&rdquo;,&ldquo;problem&rdquo;]</p> <p><strong>Explanation:</strong></p> <p>In this example we split as follows:</p> <p>&ldquo;$easy$&rdquo; splits into &ldquo;easy&rdquo; (excluding empty strings)</p> <p>&ldquo;$problem$&rdquo; splits into &ldquo;problem&rdquo; (excluding empty strings)</p> <p>Hence, the resulting array is [&ldquo;easy&rdquo;,&ldquo;problem&rdquo;].</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> words = [&ldquo;|||&rdquo;], separator = &ldquo;|&rdquo;</p> <p><strong>Output:</strong> []</p> <p><strong>Explanation:</strong></p> <p>In this example the resulting split of &ldquo;|||&rdquo; will contain only empty strings, so we return an empty array [].</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= words.length <= 100</code></li> <li><code>1 <= words[i].length <= 20</code></li> <li>characters in <code>words[i]</code> are either lowercase English letters or characters from the string <code>&quot;.,|$#@&quot;</code> (excluding the quotes)</li> <li><code>separator</code> is a character from the string <code>&quot;.,|$#@&quot;</code> (excluding the quotes)</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • splitWordsBySeparator

      public List<String> splitWordsBySeparator(List<String> words, char separator)