Leetcode Problem 2788. Split Strings by Separator

2788. Split Strings by Separator

Leetcode Solutions

Iterative Splitting Approach

  1. Initialize an empty list result to store the final split strings.
  2. Iterate over each string word in the words array. a. Initialize an empty string current to collect characters between separators. b. Iterate over each character char in word. i. If char is not the separator, append it to current. ii. If char is the separator and current is not empty, append current to result and reset current to an empty string. c. After the loop, if current is not empty, append it to result.
  3. Return the result list.
UML Thumbnail

Built-in Split Function Approach

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...