Skip to content

Commit 3fc697f

Browse files
authored
Merge pull request #639 from fartem/2496_Maximum_Value_of_a_String_in_an_Array
2024-06-05 v. 5.8.2: added "2496. Maximum Value of a String in an Array"
2 parents ec84663 + 5b772dc commit 3fc697f

4 files changed

+34
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
442442
| 2481. Minimum Cuts to Divide a Circle | [Link](https://leetcode.com/problems/minimum-cuts-to-divide-a-circle/) | [Link](./lib/easy/2481_minimum_cuts_to_divide_a_circle.rb) |
443443
| 2485. Find the Pivot Integer | [Link](https://leetcode.com/problems/find-the-pivot-integer/) | [Link](./lib/easy/2485_find_the_pivot_integer.rb) |
444444
| 2490. Circular Sentence | [Link](https://leetcode.com/problems/circular-sentence/) | [Link](./lib/easy/2490_circular_sentence.rb) |
445+
| 2496. Maximum Value of a String in an Array | [Link](https://leetcode.com/problems/maximum-value-of-a-string-in-an-array/) | [Link](./lib/easy/2496_maximum_value_of_a_string_in_an_array.rb) |

leetcode-ruby.gemspec

+1-1
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 = '5.8.1'
8+
s.version = '5.8.2'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/maximum-value-of-a-string-in-an-array/
4+
# @param {String[]} strs
5+
# @return {Integer}
6+
def maximum_value(strs)
7+
result = 0
8+
strs.each do |str|
9+
is_number = /(\D+)/.match(str).nil?
10+
11+
result =
12+
if is_number
13+
[result, str.to_i].max
14+
else
15+
[result, str.length].max
16+
end
17+
end
18+
19+
result
20+
end
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/2496_maximum_value_of_a_string_in_an_array'
5+
require 'minitest/autorun'
6+
7+
class MaximumValueOfAStringInAnArrayTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(5, maximum_value(%w[alic3 bob 3 4 00000]))
10+
assert_equal(1, maximum_value(%w[1 01 001 0001]))
11+
end
12+
end

0 commit comments

Comments
 (0)