[LeetCode] 2114. Maximum Number of Words Found in Sentences

Chobby·5일 전
1

LeetCode

목록 보기
669/710

😎풀이

  1. sentences 순회
    1-1. 각 문장에서 공백을 기준으로 단어를 분리
    1-2. 각 문장의 단어 수 확인
    1-3. 문장 내 최대 단어 수 갱신
  2. 문장 내 최대 단어 수 반환
function mostWordsFound(sentences: string[]): number {
    let mostWords = 0
    for(const sentence of sentences) {
        const curWords = sentence.match(/[\w]+/g)?.length ?? 0
        mostWords = Math.max(mostWords, curWords)
    }
    return mostWords
};
profile
내 지식을 공유할 수 있는 대담함

0개의 댓글