[leetcode, JS] 2114. Maximum Number of Words Found in Sentences

mxxn·2023년 12월 12일
0

leetcode

목록 보기
144/198

문제

문제 링크 : Maximum Number of Words Found in Sentences

풀이

/**
 * @param {string[]} sentences
 * @return {number}
 */
var mostWordsFound = function(sentences) {
    return sentences.reduce( (maxNum, sentence) => {
        return Math.max(maxNum, sentence.split(' ').length)
    }, 0)
};
  1. 배열 sentences를 reduce문을 통해 maxNum을 계산
  • Runtime 50 ms, Memory 44.53 MB
profile
내일도 글쓰기

0개의 댓글