Skip to content

Commit d7b6780

Browse files
authored
2025-03-15 v. 9.0.0: added "2109. Adding Spaces to a String"
2 parents 6a31504 + 0c2b178 commit d7b6780

File tree

4 files changed

+59
-1
lines changed

4 files changed

+59
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
733733
| 2091. Removing Minimum and Maximum From Array | [Link](https://leetcode.com/problems/removing-minimum-and-maximum-from-array/) | [Link](./lib/medium/2091_removing_minimum_and_maximum_from_array.rb) | [Link](./test/medium/test_2091_removing_minimum_and_maximum_from_array.rb) |
734734
| 2095. Delete the Middle Node of a Linked List | [Link](https://leetcode.com/problems/delete-the-middle-node-of-a-linked-list/) | [Link](./lib/medium/2095_delete_the_middle_node_of_a_linked_list.rb) | [Link](./test/medium/test_2095_delete_the_middle_node_of_a_linked_list.rb) |
735735
| 2096. Step-By-Step Directions From a Binary Tree Node to Another | [Link](https://leetcode.com/problems/step-by-step-directions-from-a-binary-tree-node-to-another/) | [Link](./lib/medium/2096_step_by_step_directions_from_a_binary_tree_node_to_another.rb) | [Link](./test/medium/test_2096_step_by_step_directions_from_a_binary_tree_node_to_another.rb) |
736+
| 2109. Adding Spaces to a String | [Link](https://leetcode.com/problems/adding-spaces-to-a-string/) | [Link](./lib/medium/2109_adding_spaces_to_a_string.rb) | [Link](./test/medium/test_2109_adding_spaces_to_a_string.rb) |
736737
| 2116. Check if a Parentheses String Can Be Valid | [Link](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | [Link](./lib/medium/2116_check_if_a_parentheses_string_can_be_valid.rb) | [Link](./test/medium/test_2116_check_if_a_parentheses_string_can_be_valid.rb) |
737738
| 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) |
738739
| 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) |

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 = '8.9.9'
8+
s.version = '9.0.0'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/adding-spaces-to-a-string/
4+
# @param {String} s
5+
# @param {Integer[]} spaces
6+
# @return {String}
7+
def add_spaces(s, spaces)
8+
start = 0
9+
result = []
10+
11+
spaces.each do |space|
12+
result << s[start...space]
13+
result << ' '
14+
start = space
15+
end
16+
17+
result << s[start..]
18+
19+
result.join
20+
end
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/2109_adding_spaces_to_a_string'
5+
require 'minitest/autorun'
6+
7+
class AddingSpacesToAStringTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
'Leetcode Helps Me Learn',
11+
add_spaces(
12+
'LeetcodeHelpsMeLearn',
13+
[8, 13, 15]
14+
)
15+
)
16+
end
17+
18+
def test_default_two
19+
assert_equal(
20+
'i code in py thon',
21+
add_spaces(
22+
'icodeinpython',
23+
[1, 5, 7, 9]
24+
)
25+
)
26+
end
27+
28+
def test_default_three
29+
assert_equal(
30+
' s p a c i n g',
31+
add_spaces(
32+
'spacing',
33+
[0, 1, 2, 3, 4, 5, 6]
34+
)
35+
)
36+
end
37+
end

0 commit comments

Comments
 (0)