[LeetCode] 2788. Split Strings by Separator

Chobby·약 10시간 전

LeetCode

목록 보기
797/800

😎풀이

  1. words 순회
    1-1. 현재 단어를 separator를 기준으로 분리
    1-2. 빈 문자열 필터링
    1-3. 분리된 배열의 각 단어를 정답 배열에 추가
  2. 정답 배열 반환
function splitWordsBySeparator(words: string[], separator: string): string[] {
    const result = []
    for(const word of words) {
        const splitted = word.split(separator).filter(a => a)
        for(const filterWord of splitted) {
            result.push(filterWord)
        }
    }
    return result
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글