Skip to content

Commit 11c30da

Browse files
committed
2025-04-07 v. 9.2.0: added "2390. Removing Stars From a String"
1 parent e66f30d commit 11c30da

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
754754
| 2295. Replace Elements in an Array | [Link](https://leetcode.com/problems/replace-elements-in-an-array/) | [Link](./lib/medium/2295_replace_elements_in_an_array.rb) | [Link](./test/medium/test_2295_replace_elements_in_an_array.rb) |
755755
| 2326. Spiral Matrix IV | [Link](https://leetcode.com/problems/spiral-matrix-iv/) | [Link](./lib/medium/2326_spiral_matrix_iv.rb) | [Link](./test/medium/test_2326_spiral_matrix_iv.rb) |
756756
| 2375. Construct Smallest Number From DI String | [Link](https://leetcode.com/problems/construct-smallest-number-from-di-string/) | [Link](./lib/medium/2375_construct_smallest_number_from_di_string.rb) | [Link](./test/medium/test_2375_construct_smallest_number_from_di_string.rb) |
757+
| 2390. Removing Stars From a String | [Link](https://leetcode.com/problems/removing-stars-from-a-string/) | [Link](./lib/medium/2390_removing_stars_from_a_string.rb) | [Link](./test/medium/test_2390_removing_stars_from_a_string.rb) |
757758
| 2425. Bitwise XOR of All Pairings | [Link](https://leetcode.com/problems/bitwise-xor-of-all-pairings/) | [Link](./lib/medium/2425_bitwise_xor_of_all_pairings.rb) | [Link](./test/medium/test_2425_bitwise_xor_of_all_pairings.rb) |
758759
| 2429. Minimize XOR | [Link](https://leetcode.com/problems/minimize-xor/) | [Link](./lib/medium/2429_minimize_xor.rb) | [Link](./test/medium/test_2429_minimize_xor.rb) |
759760
| 2657. Find the Prefix Common Array of Two Arrays | [Link](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/) | [Link](./lib/medium/2657_find_the_prefix_common_array_of_two_arrays.rb) | [Link](./test/medium/test_2657_find_the_prefix_common_array_of_two_arrays.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.1.9'
8+
s.version = '9.2.0'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/removing-stars-from-a-string/
4+
# @param {String} s
5+
# @return {String}
6+
def remove_stars(s)
7+
stack = []
8+
9+
s.each_char do |char|
10+
if char == '*'
11+
stack.pop unless stack.empty?
12+
else
13+
stack.push(char)
14+
end
15+
end
16+
17+
stack.join
18+
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/medium/2390_removing_stars_from_a_string'
5+
require 'minitest/autorun'
6+
7+
class RemovingStarsFromAStringTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
'lecoe',
11+
remove_stars(
12+
'leet**cod*e'
13+
)
14+
)
15+
end
16+
17+
def test_default_two
18+
assert_equal(
19+
'',
20+
remove_stars(
21+
'erase*****'
22+
)
23+
)
24+
end
25+
end

0 commit comments

Comments
 (0)