Skip to content

2025-04-09 v. 9.2.2: added "3498. Reverse Degree of a String" #1011

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 9, 2025
Merged
Show file tree
Hide file tree
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
Expand Up @@ -453,6 +453,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2540. Minimum Common Value | [Link](https://leetcode.com/problems/minimum-common-value/) | [Link](./lib/easy/2540_minimum_common_value.rb) | [Link](./test/easy/test_2540_minimum_common_value.rb) |
| 2544. Alternating Digit Sum | [Link](https://leetcode.com/problems/alternating-digit-sum/) | [Link](./lib/easy/2544_alternating_digit_sum.rb) | [Link](./test/easy/test_2544_alternating_digit_sum.rb) |
| 2549. Count Distinct Numbers on Board | [Link](https://leetcode.com/problems/count-distinct-numbers-on-board/) | [Link](./lib/easy/2549_count_distinct_numbers_on_board.rb) | [Link](./test/easy/test_2549_count_distinct_numbers_on_board.rb) |
| 3498. Reverse Degree of a String | [Link](https://leetcode.com/problems/reverse-degree-of-a-string/) | [Link](./lib/easy/3498_reverse_degree_of_a_string.rb) | [Link](./test/easy/test_3498_reverse_degree_of_a_string.rb) |

### Medium

Expand Down
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '9.2.1'
s.version = '9.2.2'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
17 changes: 17 additions & 0 deletions lib/easy/3498_reverse_degree_of_a_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

# https://leetcode.com/problems/reverse-degree-of-a-string/
# @param {String} s
# @return {Integer}
def reverse_degree(s)
result = 0

(0...s.size).each do |i|
c = s[i]
val = (c.ord - 123).abs * (i + 1)

result += val
end

result
end
25 changes: 25 additions & 0 deletions test/easy/test_3498_reverse_degree_of_a_string.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/3498_reverse_degree_of_a_string'
require 'minitest/autorun'

class ReverseDegreeOfAStringTest < ::Minitest::Test
def test_default_one
assert_equal(
148,
reverse_degree(
'abc'
)
)
end

def test_default_two
assert_equal(
160,
reverse_degree(
'zaza'
)
)
end
end