본문 바로가기
python-algorithm

leetcode 2788. Split Strings by Separator

by 무적김두칠 2024. 1. 2.

https://leetcode.com/problems/split-strings-by-separator/description/

 

Split Strings by Separator - LeetCode

Can you solve this real interview question? Split Strings by Separator - Given an array of strings words and a character separator, split each string in words by separator. Return an array of strings containing the new strings formed after the splits, excl

leetcode.com

 

1
2
3
4
5
6
7
8
9
class Solution:
    def splitWordsBySeparator(self, words: List[str], separator: str-> List[str]:
        answer = []
        for x in words:
            x = x.replace(separator, ' ')
            answer.extend(x.split())
        
        return answer
        
cs
반응형

댓글