Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 07dc1ae

Browse files
authored
2025年04月17日 v. 9.2.8: added "3083. Existence of a Substring in a String and Its Reverse"
2 parents c4dfc8c + ce3ca0a commit 07dc1ae

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
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
| 3131. Find the Integer Added to Array I | [Link](https://leetcode.com/problems/find-the-integer-added-to-array-i/) | [Link](./lib/easy/3131_find_the_integer_added_to_array_i.rb) | [Link](./test/easy/test_3131_find_the_integer_added_to_array_i.rb) |
460461
| 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) |
Lines changed: 17 additions & 0 deletions
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
Lines changed: 31 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /