Skip to content

Commit 82ae564

Browse files
committed
2025-01-13 v. 7.9.4: added "3223. Minimum Length of String After Operations"
1 parent 42e89da commit 82ae564

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
642642
| 916. Word Subsets | [Link](https://leetcode.com/problems/word-subsets/) | [Link](./lib/medium/916_word_subsets.rb) | [Link](./test/medium/test_916_word_subsets.rb) |
643643
| 1400. Construct K Palindrome Strings | [Link](https://leetcode.com/problems/construct-k-palindrome-strings/) | [Link](./lib/medium/1400_construct_k_palindrome_strings.rb) | [Link](./test/medium/test_1400_construct_k_palindrome_strings.rb) |
644644
| 2116. Check if a Parentheses String Can Be Valid | [Link](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | [Link](./lib/medium/2116_check_if_a_parentheses_string_can_be_valid.rb) | [Link](./test/medium/test_2116_check_if_a_parentheses_string_can_be_valid.rb) |
645+
| 3223. Minimum Length of String After Operations | [Link](https://leetcode.com/problems/minimum-length-of-string-after-operations/) | [Link](./lib/medium/3223_minimum_length_of_string_after_operations.rb) | [Link](./test/medium/test_3223_minimum_length_of_string_after_operations.rb) |
645646

646647
### Hard
647648

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 = '7.9.3'
8+
s.version = '7.9.4'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/minimum-length-of-string-after-operations/
4+
# @param {String} s
5+
# @return {Integer}
6+
def minimum_length(s)
7+
count = ::Hash.new(0)
8+
minus = 0
9+
10+
s.each_char { |c| count[c] += 1 }
11+
12+
count.each_value do |freq|
13+
while freq >= 3
14+
minus += 2
15+
freq -= 2
16+
end
17+
end
18+
19+
s.size - minus
20+
end
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/3223_minimum_length_of_string_after_operations'
5+
require 'minitest/autorun'
6+
7+
class MinimumLengthOfStringAfterOperationsTest < ::Minitest::Test
8+
def test_default_one = assert_equal(5, minimum_length('abaacbcbb'))
9+
10+
def test_default_two = assert_equal(2, minimum_length('aa'))
11+
end

0 commit comments

Comments
 (0)