-
Leetcode 2114. Maximum Number of Words Found in Sentences개발/Leetcode 2023. 7. 2. 10:54
https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/description/
Maximum Number of Words Found in Sentences - LeetCode
Can you solve this real interview question? Maximum Number of Words Found in Sentences - A sentence is a list of words that are separated by a single space with no leading or trailing spaces. You are given an array of strings sentences, where each sentenc
leetcode.com
문제
접두와 접미에 공백이 들어가지 않고 각 word간 공백으로 구분되어 있는 sentence가 담긴 배열이 있다.
문자열로 이러우진 배열 sentences가 주어지며 각 원소는 sentence가 있다.
각 sentence에 있는 최다 word의 개수를 반환하여라
코드
import re
class Solution:def mostWordsFound(self, sentences: list[str]) -> int:a = 0for sen in sentences:a = max(len(re.split(r'\s', sen)), a)return a'개발 > Leetcode' 카테고리의 다른 글
Leetcode 137. Single Number II (0) 2023.07.04 Leetcode 859. Buddy Strings (0) 2023.07.03 Leetcode 1678. Goal Parser Interpretation (0) 2023.07.02 Leetcode 744. Find Smallest Letter Greater Than Target (0) 2023.07.02 Leetcode 2011. Final Value of Variable After Performing Operations (0) 2023.07.02