Skip to content

Commit ce3ca0a

Browse files
committed
2025-04-17 v. 9.2.8: added "3083. Existence of a Substring in a String and Its Reverse"
1 parent a808dfb commit ce3ca0a

4 files changed

+50
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
455455
| 2549. Count Distinct Numbers on Board | [Link](https://leetcode.com/problems/count-distinct-numbers-on-board/) | [Link](./lib/easy/2549_count_distinct_numbers_on_board.rb) | [Link](./test/easy/test_2549_count_distinct_numbers_on_board.rb) |
456456
| 2652. Sum Multiples | [Link](https://leetcode.com/problems/sum-multiples/) | [Link](./lib/easy/2652_sum_multiples.rb) | [Link](./test/easy/test_2652_sum_multiples.rb) |
457457
| 2974. Minimum Number Game | [Link](https://leetcode.com/problems/minimum-number-game/) | [Link](./lib/easy/2974_minimum_number_game.rb) | [Link](./test/easy/test_2974_minimum_number_game.rb) |
458+
| 3083. Existence of a Substring in a String and Its Reverse | [Link](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/) | [Link](./lib/easy/3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) | [Link](./test/easy/test_3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) |
458459
| 3110. Score of a String | [Link](https://leetcode.com/problems/score-of-a-string/) | [Link](./lib/easy/3110_score_of_a_string.rb) | [Link](./test/easy/test_3110_score_of_a_string.rb) |
459460
| 3136. Valid Word | [Link](https://leetcode.com/problems/valid-word/) | [Link](./lib/easy/3136_valid_word.rb) | [Link](./test/easy/test_3136_valid_word.rb) |
460461
| 3151. Special Array I | [Link](https://leetcode.com/problems/special-array-i/) | [Link](./lib/easy/3151_special_array_i.rb) | [Link](./test/easy/test_3151_special_array_i.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 = '9.2.7'
8+
s.version = '9.2.8'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/
4+
# @param {String} s
5+
# @return {Boolean}
6+
def is_substring_present(s)
7+
return false if s.size < 2
8+
9+
rev = s.reverse
10+
subs = []
11+
12+
(0..s.length - 2).each do |i|
13+
subs << s[i, 2]
14+
end
15+
16+
subs.any? { |sub| rev.include?(sub) }
17+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/3083_existence_of_a_substring_in_a_string_and_its_reverse'
5+
require 'minitest/autorun'
6+
7+
class ExistenceOfASubstringInAStringAndItsReverseTest < ::Minitest::Test
8+
def test_default_one
9+
assert(
10+
is_substring_present(
11+
'leetcode'
12+
)
13+
)
14+
end
15+
16+
def test_default_two
17+
assert(
18+
is_substring_present(
19+
'abcba'
20+
)
21+
)
22+
end
23+
24+
def test_default_three
25+
assert(
26+
!is_substring_present(
27+
'abcd'
28+
)
29+
)
30+
end
31+
end

0 commit comments

Comments
 (0)