Skip to content

Commit cea8b0e

Browse files
authored
Merge pull request #570 from fartem/2114_Maximum_Number_of_Words_Found_in_Sentences
2024-02-28 v. 5.1.4: added "2114. Maximum Number of Words Found in Sentences"
2 parents e92c1aa + b407f42 commit cea8b0e

4 files changed

+25
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,3 +374,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
374374
| 2099. Find Subsequence of Length K With the Largest Sum | [Link](https://leetcode.com/problems/find-subsequence-of-length-k-with-the-largest-sum/) | [Link](./lib/easy/2099_find_subsequence_of_length_k_with_the_largest_sum.rb) |
375375
| 2103. Rings and Rods | [Link](https://leetcode.com/problems/rings-and-rods/) | [Link](./lib/easy/2103_rings_and_rods.rb) |
376376
| 2108. Find First Palindromic String in the Array | [Link](https://leetcode.com/problems/find-first-palindromic-string-in-the-array/) | [Link](./lib/easy/2108_find_first_palindromic_string_in_the_array.rb) |
377+
| 2114. Maximum Number of Words Found in Sentences | [Link](https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/) | [Link](./lib/easy/2114_maximum_number_of_words_round_in_sentences.rb) |

leetcode-ruby.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ require 'English'
55
::Gem::Specification.new do |s|
66
s.required_ruby_version = '>= 3.0'
77
s.name = 'leetcode-ruby'
8-
s.version = '5.1.3'
8+
s.version = '5.1.4'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/maximum-number-of-words-found-in-sentences/
4+
# @param {String[]} sentences
5+
# @return {Integer}
6+
def most_words_found(sentences)
7+
sentences.map { |sentence| sentence.count(' ') }.max + 1
8+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2114_maximum_number_of_words_round_in_sentences'
5+
require 'minitest/autorun'
6+
7+
class MaximumNumberOfWordsRoundInSentencesTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(
10+
6,
11+
most_words_found(['alice and bob love leetcode', 'i think so too', 'this is great thanks very much'])
12+
)
13+
assert_equal(3, most_words_found(['please wait', 'continue to fight', 'continue to win']))
14+
end
15+
end

0 commit comments

Comments
 (0)