Skip to content

2024-04-10 v. 5.4.3: added "2278. Percentage of Letter in String" #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -403,3 +403,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2255. Count Prefixes of a Given String | [Link](https://leetcode.com/problems/count-prefixes-of-a-given-string/) | [Link](./lib/easy/2255_count_prefixes_of_a_given_string.rb) |
| 2259. Remove Digit From Number to Maximize Result | [Link](https://leetcode.com/problems/remove-digit-from-number-to-maximize-result/) | [Link](./lib/easy/2259_remove_digit_from_number_to_maximize_result.rb) |
| 2264. Largest 3-Same-Digit Number in String | [Link](https://leetcode.com/problems/largest-3-same-digit-number-in-string/) | [Link](./lib/easy/2264_largest_3_same_digit_number_in_string.rb) |
| 2278. Percentage of Letter in String | [Link](https://leetcode.com/problems/percentage-of-letter-in-string/) | [Link](./lib/easy/2278_percentage_of_letter_in_string.rb) |
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '5.4.2'
s.version = '5.4.3'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
9 changes: 9 additions & 0 deletions lib/easy/2278_percentage_of_letter_in_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

# https://leetcode.com/problems/percentage-of-letter-in-string/
# @param {String} s
# @param {Character} letter
# @return {Integer}
def percentage_letter(s, letter)
(s.count(letter).to_f / s.length * 100).to_i
end
12 changes: 12 additions & 0 deletions test/easy/test_2278_percentage_of_letter_in_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/2278_percentage_of_letter_in_string'
require 'minitest/autorun'

class PercentageOfLetterInStringTest < ::Minitest::Test
def test_default
assert_equal(33, percentage_letter('foobar', 'o'))
assert_equal(0, percentage_letter('jjjj', 'k'))
end
end