diff --git a/README.md b/README.md index 9420ceee..b7cde933 100644 --- a/README.md +++ b/README.md @@ -728,6 +728,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/). | 2007. Find Original Array From Doubled Array | [Link](https://leetcode.com/problems/find-original-array-from-doubled-array/) | [Link](./lib/medium/2007_find_original_array_from_doubled_array.rb) | [Link](./test/medium/test_2007_find_original_array_from_doubled_array.rb) | | 2023. Number of Pairs of Strings With Concatenation Equal to Target | [Link](https://leetcode.com/problems/number-of-pairs-of-strings-with-concatenation-equal-to-target/) | [Link](./lib/medium/2023_number_of_pairs_of_strings_with_concatenation_equal_to_target.rb) | [Link](./test/medium/test_2023_number_of_pairs_of_strings_with_concatenation_equal_to_target.rb) | | 2058. Find the Minimum and Maximum Number of Nodes Between Critical Points | [Link](https://leetcode.com/problems/find-the-minimum-and-maximum-number-of-nodes-between-critical-points/) | [Link](./lib/medium/2058_find_the_minimum_and_maximum_number_of_nodes_between_critical_points.rb) | [Link](./test/medium/test_2058_find_the_minimum_and_maximum_number_of_nodes_between_critical_points.rb) | +| 2063. Vowels of All Substrings | [Link](https://leetcode.com/problems/vowels-of-all-substrings/) | [Link](./lib/medium/2063_vowels_of_all_substrings.rb) | [Link](./test/medium/test_2063_vowels_of_all_substrings.rb) | | 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) | | 2425. Bitwise XOR of All Pairings | [Link](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | [Link](./lib/medium/2425_bitwise_xor_of_all_pairings.rb) | [Link](./test/medium/test_2425_bitwise_xor_of_all_pairings.rb) | | 2429. Minimize XOR | [Link](https://leetcode.com/problems/minimize-xor/) | [Link](./lib/medium/2429_minimize_xor.rb) | [Link](./test/medium/test_2429_minimize_xor.rb) | diff --git a/leetcode-ruby.gemspec b/leetcode-ruby.gemspec index 6a5b6b5e..47f6d514 100644 --- a/leetcode-ruby.gemspec +++ b/leetcode-ruby.gemspec @@ -5,7 +5,7 @@ require 'English' ::Gem::Specification.new do |s| s.required_ruby_version = '>= 3.0' s.name = 'leetcode-ruby' - s.version = '8.9.4' + s.version = '8.9.5' s.license = 'MIT' s.files = ::Dir['lib/**/*.rb'] + %w[README.md] s.executable = 'leetcode-ruby' diff --git a/lib/medium/2063_vowels_of_all_substrings.rb b/lib/medium/2063_vowels_of_all_substrings.rb new file mode 100644 index 00000000..5f086fe6 --- /dev/null +++ b/lib/medium/2063_vowels_of_all_substrings.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +# https://leetcode.com/problems/vowels-of-all-substrings/ +# @param {String} word +# @return {Integer} +def count_vowels(word) + vowels = %w[a e i o u] + result = 0 + + word.chars.each_with_index do |char, i| + result += (i + 1) * (word.size - i) if vowels.include?(char.downcase) + end + + result +end diff --git a/test/medium/test_2063_vowels_of_all_substrings.rb b/test/medium/test_2063_vowels_of_all_substrings.rb new file mode 100644 index 00000000..b80ede7d --- /dev/null +++ b/test/medium/test_2063_vowels_of_all_substrings.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require_relative '../test_helper' +require_relative '../../lib/medium/2063_vowels_of_all_substrings' +require 'minitest/autorun' + +class VowelsOfAllSubstringsTest < ::Minitest::Test + def test_default_one = assert_equal(6, count_vowels('aba')) + + def test_default_two = assert_equal(3, count_vowels('abc')) + + def test_default_three = assert_equal(0, count_vowels('ltcd')) +end