Skip to content

Commit dcc9b2d

Browse files
committed
2025-03-04 v. 9.1.9: added "2375. Construct Smallest Number From DI
String"
1 parent e922c83 commit dcc9b2d

6 files changed

+47
-1
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ Style/DisableCopsWithinSourceCodeDirective:
2222
Enabled: false
2323
Style/IpAddresses:
2424
Enabled: false
25+
Style/NestedModifier:
26+
Enabled: false
2527

2628
Bundler/GemComment:
2729
Enabled: false

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ gem 'prime', '0.1.2'
88
gem 'rake', '12.3.3'
99
gem 'rubocop', '1.7.0'
1010
gem 'simplecov', '0.22.0'
11+
gem 'solargraph', '0.44.0'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
753753
| 2266. Count Number of Texts | [Link](https://leetcode.com/problems/count-number-of-texts/) | [Link](./lib/medium/2266_count_number_of_texts.rb) | [Link](./test/medium/test_2266_count_number_of_texts.rb) |
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) |
756+
| 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) |
756757
| 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) |
757758
| 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) |
758759
| 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.8'
8+
s.version = '9.1.9'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/construct-smallest-number-from-di-string/
4+
# @param {String} pattern
5+
# @return {String}
6+
def smallest_number2375(pattern)
7+
stack = [1]
8+
result = ''
9+
10+
(0..pattern.size).each do |i|
11+
result += stack.pop.to_s until stack.empty? if i == pattern.size || pattern[i] == 'I'
12+
13+
stack.push(i + 2)
14+
end
15+
16+
result
17+
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/2375_construct_smallest_number_from_di_string'
5+
require 'minitest/autorun'
6+
7+
class ConstructSmallestNumberFromDIStringTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
'123549876',
11+
smallest_number2375(
12+
'IIIDIDDD'
13+
)
14+
)
15+
end
16+
17+
def test_default_two
18+
assert_equal(
19+
'4321',
20+
smallest_number2375(
21+
'DDD'
22+
)
23+
)
24+
end
25+
end

0 commit comments

Comments
 (0)