|
| 1 | +<h2><a href="https://leetcode.com/problems/split-strings-by-separator">2881. Split Strings by Separator</a></h2><h3>Easy</h3><hr><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> |
| 2 | + |
| 3 | +<p>Return <em>an array of strings containing the new strings formed after the splits, <strong>excluding empty strings</strong>.</em></p> |
| 4 | + |
| 5 | +<p><strong>Notes</strong></p> |
| 6 | + |
| 7 | +<ul> |
| 8 | + <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> |
| 9 | + <li>A split may result in more than two strings.</li> |
| 10 | + <li>The resulting strings must maintain the same order as they were initially given.</li> |
| 11 | +</ul> |
| 12 | + |
| 13 | +<p> </p> |
| 14 | +<p><strong class="example">Example 1:</strong></p> |
| 15 | + |
| 16 | +<pre> |
| 17 | +<strong>Input:</strong> words = ["one.two.three","four.five","six"], separator = "." |
| 18 | +<strong>Output:</strong> ["one","two","three","four","five","six"] |
| 19 | +<strong>Explanation: </strong>In this example we split as follows: |
| 20 | + |
| 21 | +"one.two.three" splits into "one", "two", "three" |
| 22 | +"four.five" splits into "four", "five" |
| 23 | +"six" splits into "six" |
| 24 | + |
| 25 | +Hence, the resulting array is ["one","two","three","four","five","six"].</pre> |
| 26 | + |
| 27 | +<p><strong class="example">Example 2:</strong></p> |
| 28 | + |
| 29 | +<pre> |
| 30 | +<strong>Input:</strong> words = ["$easy$","$problem$"], separator = "$" |
| 31 | +<strong>Output:</strong> ["easy","problem"] |
| 32 | +<strong>Explanation:</strong> In this example we split as follows: |
| 33 | + |
| 34 | +"$easy$" splits into "easy" (excluding empty strings) |
| 35 | +"$problem$" splits into "problem" (excluding empty strings) |
| 36 | + |
| 37 | +Hence, the resulting array is ["easy","problem"]. |
| 38 | +</pre> |
| 39 | + |
| 40 | +<p><strong class="example">Example 3:</strong></p> |
| 41 | + |
| 42 | +<pre> |
| 43 | +<strong>Input:</strong> words = ["|||"], separator = "|" |
| 44 | +<strong>Output:</strong> [] |
| 45 | +<strong>Explanation:</strong> In this example the resulting split of "|||" will contain only empty strings, so we return an empty array []. </pre> |
| 46 | + |
| 47 | +<p> </p> |
| 48 | +<p><strong>Constraints:</strong></p> |
| 49 | + |
| 50 | +<ul> |
| 51 | + <li><code>1 <= words.length <= 100</code></li> |
| 52 | + <li><code>1 <= words[i].length <= 20</code></li> |
| 53 | + <li>characters in <code>words[i]</code> are either lowercase English letters or characters from the string <code>".,|$#@"</code> (excluding the quotes)</li> |
| 54 | + <li><code>separator</code> is a character from the string <code>".,|$#@"</code> (excluding the quotes)</li> |
| 55 | +</ul> |
0 commit comments