Skip to content

Commit 3991e6c

Browse files
committed
2024-06-04 v. 5.8.1: added "2490. Circular Sentence"
1 parent d7abb99 commit 3991e6c

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -441,3 +441,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
441441
| 2475. Number of Unequal Triplets in Array | [Link](https://leetcode.com/problems/number-of-unequal-triplets-in-array/) | [Link](./lib/easy/2475_number_of_unequal_triplets_in_array.rb) |
442442
| 2481. Minimum Cuts to Divide a Circle | [Link](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle/) | [Link](./lib/easy/2481_minimum_cuts_to_divide_a_circle.rb) |
443443
| 2485. Find the Pivot Integer | [Link](https://leetcode.com/problems/find-the-pivot-integer/) | [Link](./lib/easy/2485_find_the_pivot_integer.rb) |
444+
| 2490. Circular Sentence | [Link](https://leetcode.com/problems/circular-sentence/) | [Link](./lib/easy/2490_circular_sentence.rb) |

leetcode-ruby.gemspec

+1-1
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.8.0'
8+
s.version = '5.8.1'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'

lib/easy/2490_circular_sentence.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/circular-sentence/
4+
# @param {String} sentence
5+
# @return {Boolean}
6+
def is_circular_sentence(sentence)
7+
words = sentence.split
8+
first = words.first
9+
curr = first[first.length - 1]
10+
words.drop(1).each do |word|
11+
return false unless word[0] == curr
12+
13+
curr = word[word.length - 1]
14+
end
15+
16+
curr == first[0]
17+
end
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2490_circular_sentence'
5+
require 'minitest/autorun'
6+
7+
class CircularSentenceTest < ::Minitest::Test
8+
def test_default
9+
assert(is_circular_sentence('leetcode exercises sound delightful'))
10+
assert(is_circular_sentence('eetcode'))
11+
assert(!is_circular_sentence('Leetcode is cool'))
12+
end
13+
end

0 commit comments

Comments
 (0)