Skip to content

Commit c72d781

Browse files
committed
2023-06-14 v. 0.8.2: added "434. Number of Segments in a String"
1 parent 471948d commit c72d781

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
9494
| 412. Fizz Buzz | [Link](https://leetcode.com/problems/fizz-buzz/) | [Link](./lib/easy/412_fizz_buzz.rb) |
9595
| 414. Third Maximum Number | [Link](https://leetcode.com/problems/third-maximum-number/) | [Link](./lib/easy/414_third_maximum_number.rb) |
9696
| 415. Add Strings | [Link](https://leetcode.com/problems/add-strings/) | [Link](./lib/easy/415_add_strings.rb) |
97+
| 434. Number of Segments in a String | [Link](https://leetcode.com/problems/number-of-segments-in-a-string/) | [Link](./lib/easy/434_number_of_segments_in_a_string.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 = '0.8.1'
8+
s.version = '0.8.2'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
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/number-of-segments-in-a-string/
4+
# @param {String} s
5+
# @return {Integer}
6+
def count_segments(s)
7+
s.split.length
8+
end
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/434_number_of_segments_in_a_string'
5+
require 'minitest/autorun'
6+
7+
class NumberOfSegmentsInAStringTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(5, count_segments('Hello, my name is John'))
10+
assert_equal(1, count_segments('Hello'))
11+
end
12+
end

0 commit comments

Comments
 (0)