Skip to content

Commit deaa436

Browse files
committed
2023-08-30 v. 2.5.9: added "1078. Occurrences After Bigram"
1 parent f6b79d1 commit deaa436

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
205205
| 1047. Remove All Adjacent Duplicates In String | [Link](https://leetcode.com/problems/remove-all-adjacent-duplicates-in-string/) | [Link](./lib/easy/1047_remove_all_adjacent_duplicates_in_string.rb) |
206206
| 1051. Height Checker | [Link](https://leetcode.com/problems/height-checker/) | [Link](./lib/easy/1051_height_checker.rb) |
207207
| 1071. Greatest Common Divisor of Strings | [Link](https://leetcode.com/problems/greatest-common-divisor-of-strings/) | [Link](./lib/easy/1071_greatest_common_divisor_of_strings.rb) |
208+
| 1078. Occurrences After Bigram | [Link](https://leetcode.com/problems/occurrences-after-bigram/) | [Link](./lib/easy/1078_occurrences_after_bigram.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 = '2.5.8'
8+
s.version = '2.5.9'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/occurrences-after-bigram/
4+
# @param {String} text
5+
# @param {String} first
6+
# @param {String} second
7+
# @return {String[]}
8+
def find_occurrences(text, first, second)
9+
result = []
10+
words = text.split
11+
(0...words.length - 2).each do |i|
12+
result << words[i + 2] if words[i] == first && words[i + 1] == second
13+
end
14+
15+
result
16+
end
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/1078_occurrences_after_bigram'
5+
require 'minitest/autorun'
6+
7+
class OccurrencesAfterBigramTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(
10+
%w[girl student],
11+
find_occurrences(
12+
'alice is a good girl she is a good student',
13+
'a',
14+
'good'
15+
)
16+
)
17+
assert_equal(
18+
%w[we rock],
19+
find_occurrences(
20+
'we will we will rock you',
21+
'we',
22+
'will'
23+
)
24+
)
25+
end
26+
end

0 commit comments

Comments
 (0)