From 2fbf8a44f0d405b7bb8c0ab4d075e2a824aebc62 Mon Sep 17 00:00:00 2001 From: fartem Date: Tue, 14 Jan 2025 13:23:14 +0300 Subject: [PATCH] 2025-01-14 v. 8.0.4: added "1220. Count Vowels Permutation" --- README.md | 1 + leetcode-ruby.gemspec | 2 +- lib/hard/1220_count_vowels_permutation.rb | 29 +++++++++++++++++++ .../test_1220_count_vowels_permutation.rb | 13 +++++++++ 4 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 lib/hard/1220_count_vowels_permutation.rb create mode 100644 test/hard/test_1220_count_vowels_permutation.rb diff --git a/README.md b/README.md index baf89a06..31a3a7cc 100644 --- a/README.md +++ b/README.md @@ -673,3 +673,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/). | 936. Stamping The Sequence | [Link](https://leetcode.com/problems/stamping-the-sequence/) | [Link](./lib/hard/936_stamping_the_sequence.rb) | [Link](./test/hard/test_936_stamping_the_sequence.rb) | | 968. Binary Tree Cameras | [Link](https://leetcode.com/problems/binary-tree-cameras/) | [Link](./lib/hard/968_binary_tree_cameras.rb) | [Link](./test/hard/test_968_binary_tree_cameras.rb) | | 1106. Parsing A Boolean Expression | [Link](https://leetcode.com/problems/parsing-a-boolean-expression/) | [Link](./lib/hard/1106_parsing_a_boolean_expression.rb) | [Link](./test/hard/test_1106_parsing_a_boolean_expression.rb) | +| 1220. Count Vowels Permutation | [Link](https://leetcode.com/problems/count-vowels-permutation/) | [Link](./lib/hard/1220_count_vowels_permutation.rb) | [Link](./test/hard/test_1220_count_vowels_permutation.rb) | diff --git a/leetcode-ruby.gemspec b/leetcode-ruby.gemspec index 248a148c..0eb4e120 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.0.3' + s.version = '8.0.4' s.license = 'MIT' s.files = ::Dir['lib/**/*.rb'] + %w[README.md] s.executable = 'leetcode-ruby' diff --git a/lib/hard/1220_count_vowels_permutation.rb b/lib/hard/1220_count_vowels_permutation.rb new file mode 100644 index 00000000..c47fe489 --- /dev/null +++ b/lib/hard/1220_count_vowels_permutation.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: false + +# https://leetcode.com/problems/count-vowels-permutation/ +# @param {Integer} n +# @return {Integer} +def count_vowel_permutation(n) + a = 1 + e = 1 + i = 1 + o = 1 + u = 1 + mod = 10**9 + 7 + + (2..n).each do + a2 = (e + i + u) % mod + e2 = (a + i) % mod + i2 = (e + o) % mod + o2 = i + u2 = (o + i) % mod + + a = a2 + e = e2 + i = i2 + o = o2 + u = u2 + end + + (a + e + i + o + u) % mod +end diff --git a/test/hard/test_1220_count_vowels_permutation.rb b/test/hard/test_1220_count_vowels_permutation.rb new file mode 100644 index 00000000..226963c5 --- /dev/null +++ b/test/hard/test_1220_count_vowels_permutation.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: false + +require_relative '../test_helper' +require_relative '../../lib/hard/1220_count_vowels_permutation' +require 'minitest/autorun' + +class CountVowelsPermutationTest < ::Minitest::Test + def test_default_one = assert(5, count_vowel_permutation(1)) + + def test_default_two = assert(10, count_vowel_permutation(2)) + + def test_default_three = assert(68, count_vowel_permutation(5)) +end