#2114

Donghee Choi·2023년 2월 1일

leetcode

목록 보기
13/13

2114. Maximum Number of Words Found in Sentences

내 답안

/**
 * @param {string[]} sentences
 * @return {number}
 */
var mostWordsFound = function (sentences) {
  let max = 0;
  sentences.forEach((sentence) => {
    let words = sentence.split(' ');
    max = Math.max(max, words.length);
  });
  return max;
};

split뒤에 바로 length를 붙여서 사용하면 코드를 줄일수있다.

profile
frontend, vuejs, react, docker, kubernetes

0개의 댓글