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 6c99554

Browse files
committed
2025年04月21日 v. 9.3.0: added "3090. Maximum Length Substring With Two Occurrences"
1 parent c71fa18 commit 6c99554

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
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) |
458458
| 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) |
459+
| 3090. Maximum Length Substring With Two Occurrences | [Link](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences/) | [Link](./lib/easy/3090_maximum_length_substring_with_two_occurrences.rb) | [Link](./test/easy/test_3090_maximum_length_substring_with_two_occurrences.rb) |
459460
| 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) |
460461
| 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) |
461462
| 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) |

‎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 = '9.2.9.1'
8+
s.version = '9.3.0'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/maximum-length-substring-with-two-occurrences/
4+
# @param {String} s
5+
# @return {Integer}
6+
def maximum_length_substring(s)
7+
max_len = 0
8+
left = 0
9+
char_count = ::Hash.new(0)
10+
11+
s.each_char.with_index do |char, right|
12+
char_count[char] += 1
13+
14+
while char_count[char] > 2
15+
char_count[s[left]] -= 1
16+
left += 1
17+
end
18+
19+
current_len = right - left + 1
20+
max_len = [max_len, current_len].max
21+
end
22+
23+
max_len
24+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/3090_maximum_length_substring_with_two_occurrences'
5+
require 'minitest/autorun'
6+
7+
class MaximumLengthSubstringWithTwoOccurrencesTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
4,
11+
maximum_length_substring(
12+
'bcbbbcba'
13+
)
14+
)
15+
end
16+
17+
def test_default_two
18+
assert_equal(
19+
2,
20+
maximum_length_substring(
21+
'aaaa'
22+
)
23+
)
24+
end
25+
end

0 commit comments

Comments
(0)

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