Skip to content

Commit 3855de1

Browse files
committed
2024-02-15 v. 4.7.9: added "2068. Check Whether Two Strings are Almost Equivalent"
1 parent f362067 commit 3855de1

4 files changed

+34
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -365,3 +365,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
365365
| 2053. Kth Distinct String in an Array | [Link](https://leetcode.com/problems/kth-distinct-string-in-an-array/) | [Link](./lib/easy/2053_kth_distinct_string_in_an_array.rb) |
366366
| 2057. Smallest Index With Equal Value | [Link](https://leetcode.com/problems/smallest-index-with-equal-value/) | [Link](./lib/easy/2057_smallest_index_with_equal_value.rb) |
367367
| 2062. Count Vowel Substrings of a String | [Link](https://leetcode.com/problems/count-vowel-substrings-of-a-string/) | [Link](./lib/easy/2062_count_vowel_substrings_of_a_string.rb) |
368+
| 2068. Check Whether Two Strings are Almost Equivalent | [Link](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/) | [Link](./lib/easy/2068_check_whether_two_strings_are_almost_equivalent.rb) |

leetcode-ruby.gemspec

+1-1
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 = '4.7.8'
8+
s.version = '4.7.9'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/
4+
# @param {String} word1
5+
# @param {String} word2
6+
# @return {Boolean}
7+
def check_almost_equivalent(word1, word2)
8+
chars1 = ::Array.new(128, 0)
9+
chars2 = ::Array.new(128, 0)
10+
(0...word1.length).each do |i|
11+
chars1[word1[i].ord] += 1
12+
chars2[word2[i].ord] += 1
13+
end
14+
(0...chars1.length).each do |i|
15+
return false if (chars1[i] - chars2[i]).abs > 3
16+
end
17+
18+
true
19+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2068_check_whether_two_strings_are_almost_equivalent'
5+
require 'minitest/autorun'
6+
7+
class CheckWhetherTwoStringsAreAlmostEquivalentTest < ::Minitest::Test
8+
def test_default
9+
assert(!check_almost_equivalent('aaaa', 'bccb'))
10+
assert(check_almost_equivalent('abcdeef', 'abaaacc'))
11+
assert(check_almost_equivalent('cccddabba', 'babababab'))
12+
end
13+
end

0 commit comments

Comments
 (0)