Skip to content

Commit 6a2c7cc

Browse files
authored
Merge pull request #644 from fartem/2520_Count_the_Digits_That_Divide_a_Number
2024-06-12 v. 5.8.7: added "2520. Count the Digits That Divide a Number"
2 parents a673736 + ef0bfce commit 6a2c7cc

4 files changed

+31
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,3 +447,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
447447
| 2506. Count Pairs Of Similar Strings | [Link](https://leetcode.com/problems/count-pairs-of-similar-strings/) | [Link](./lib/easy/2506_count_pairs_of_similar_strings.rb) |
448448
| 2511. Maximum Enemy Forts That Can Be Captured | [Link](https://leetcode.com/problems/maximum-enemy-forts-that-can-be-captured/) | [Link](./lib/easy/2511_maximum_enemy_forts_that_can_be_captured.rb) |
449449
| 2515. Shortest Distance to Target String in a Circular Array | [Link](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array/) | [Link](./lib/easy/2515_shortest_distance_to_target_string_in_a_circular_array.rb) |
450+
| 2520. Count the Digits That Divide a Number | [Link](https://leetcode.com/problems/count-the-digits-that-divide-a-number/) | [Link](./lib/easy/2520_count_the_digits_that_divide_a_number.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 = '5.8.6'
8+
s.version = '5.8.7'
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/count-the-digits-that-divide-a-number/
4+
# @param {Integer} num
5+
# @return {Integer}
6+
def count_digits(num)
7+
original = num
8+
result = 0
9+
while num.positive?
10+
digit = num % 10
11+
result += 1 if (original % digit).zero?
12+
num /= 10
13+
end
14+
15+
result
16+
end
Lines changed: 13 additions & 0 deletions
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/2520_count_the_digits_that_divide_a_number'
5+
require 'minitest/autorun'
6+
7+
class CountTheDigitsThatDivideANumberTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(1, count_digits(7))
10+
assert_equal(2, count_digits(121))
11+
assert_equal(4, count_digits(1248))
12+
end
13+
end

0 commit comments

Comments
 (0)