Skip to content

Commit 1f90361

Browse files
committed
2024-05-27 v. 5.7.5: added "2455. Average Value of Even Numbers That Are Divisible by Three"
1 parent acf8874 commit 1f90361

4 files changed

+32
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
435435
| 2432. The Employee That Worked on the Longest Task | [Link](https://leetcode.com/problems/the-employee-that-worked-on-the-longest-task/) | [Link](./lib/easy/2432_the_employee_that_worked_on_the_longest_task.rb) |
436436
| 2441. Largest Positive Integer That Exists With Its Negative | [Link](https://leetcode.com/problems/largest-positive-integer-that-exists-with-its-negative/) | [Link](./lib/easy/2441_largest_positive_integer_that_exists_with_its_negative.rb) |
437437
| 2446. Determine if Two Events Have Conflict | [Link](https://leetcode.com/problems/determine-if-two-events-have-conflict/) | [Link](./lib/easy/2446_determine_if_two_events_have_conflict.rb) |
438+
| 2455. Average Value of Even Numbers That Are Divisible by Three | [Link](https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/) | [Link](./lib/easy/2455_average_value_of_even_numbers_that_are_divisible_by_three.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 = '5.7.4'
8+
s.version = '5.7.5'
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,18 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/average-value-of-even-numbers-that-are-divisible-by-three/
4+
# @param {Integer[]} nums
5+
# @return {Integer}
6+
def average_value(nums)
7+
count = 0
8+
sum = 0
9+
10+
nums.each do |num|
11+
next unless (num % 6).zero?
12+
13+
count += 1
14+
sum += num
15+
end
16+
17+
count.positive? ? sum / count : 0
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2455_average_value_of_even_numbers_that_are_divisible_by_three'
5+
require 'minitest/autorun'
6+
7+
class AverageValueOfEvenNumbersThatAreDivisibleByThreeTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(9, average_value([1, 3, 6, 10, 12, 15]))
10+
assert_equal(0, average_value([1, 2, 4, 7, 10]))
11+
end
12+
end

0 commit comments

Comments
 (0)