Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f3bcf33

Browse files
authored
Merge pull request #1031 from fartem/2710-Remove-Trailing-Zeros-From-a-String
2025年06月04日 v. 9.3.9: added "2710. Remove Trailing Zeros From a String"
2 parents cbc83fc + 9433c56 commit f3bcf33

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,11 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
454454
| 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) |
455455
| 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) |
456456
| 2652. Sum Multiples | [Link](https://leetcode.com/problems/sum-multiples/) | [Link](./lib/easy/2652_sum_multiples.rb) | [Link](./test/easy/test_2652_sum_multiples.rb) |
457+
| 2678. Number of Senior Citizens | [Link](https://leetcode.com/problems/number-of-senior-citizens/) | [Link](./lib/easy/2678_number_of_senior_citizens.rb) | [Link](./test/easy/test_2678_number_of_senior_citizens.rb) |
458+
| 2710. Remove Trailing Zeros From a String | [Link](https://leetcode.com/problems/remove-trailing-zeros-from-a-string/) | [Link](./lib/easy/2710_remove_trailing_zeros_from_a_string.rb) | [Link](./test/easy/test_2710_remove_trailing_zeros_from_a_string.rb) |
457459
| 2951. Find the Peaks | [Link](https://leetcode.com/problems/find-the-peaks/) | [Link](./lib/easy/2951_find_the_peaks.rb) | [Link](./test/easy/test_2951_find_the_peaks.rb) |
458460
| 2966. Divide Array Into Arrays With Max Difference | [Link](https://leetcode.com/problems/divide-array-into-arrays-with-max-difference/) | [Link](./lib/easy/2966_divide_array_into_arrays_with_max_difference.rb) | [Link](./test/easy/test_2966_divide_array_into_arrays_with_max_difference.rb) |
459461
| 2974. Minimum Number Game | [Link](https://leetcode.com/problems/minimum-number-game/) | [Link](./lib/easy/2974_minimum_number_game.rb) | [Link](./test/easy/test_2974_minimum_number_game.rb) |
460-
| 2678. Number of Senior Citizens | [Link](https://leetcode.com/problems/number-of-senior-citizens/) | [Link](./lib/easy/2678_number_of_senior_citizens.rb) | [Link](./test/easy/test_2678_number_of_senior_citizens.rb) |
461462
| 3046. Split the Array | [Link](https://leetcode.com/problems/split-the-array/) | [Link](./lib/easy/3046_split_the_array.rb) | [Link](./test/easy/test_3046_split_the_array.rb) |
462463
| 3083. Existence of a Substring in a String and Its Reverse | [Link](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/) | [Link](./lib/easy/3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) | [Link](./test/easy/test_3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) |
463464
| 3090. Maximum Length Substring With Two Occurrences | [Link](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences/) | [Link](./lib/easy/3090_maximum_length_substring_with_two_occurrences.rb) | [Link](./test/easy/test_3090_maximum_length_substring_with_two_occurrences.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 = '9.3.8'
8+
s.version = '9.3.9'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/remove-trailing-zeros-from-a-string/
4+
# @param {String} num
5+
# @return {String}
6+
def remove_trailing_zeros(num)
7+
num.sub(/0+$/, '')
8+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2710_remove_trailing_zeros_from_a_string'
5+
require 'minitest/autorun'
6+
7+
class RemoveTrailingZerosFromAStringTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
'512301',
11+
remove_trailing_zeros(
12+
'51230100'
13+
)
14+
)
15+
end
16+
17+
def test_default_two
18+
assert_equal(
19+
'123',
20+
remove_trailing_zeros(
21+
'123'
22+
)
23+
)
24+
end
25+
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /