Skip to content

Commit b37be8e

Browse files
authored
Merge pull request #646 from fartem/2529_Maximum_Count_of_Positive_Integer_and_Negative_Integer
2024-06-14 v. 5.8.9: added "2529. Maximum Count of Positive Integer and Negative Integer"
2 parents 3484704 + c32e6d9 commit b37be8e

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,3 +449,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
449449
| 2515. Shortest Distance to Target String in a Circular Array | [Link](https://leetcode.com/problems/shortest-distance-to-target-string-in-a-circular-array/) | [Link](./lib/easy/2515_shortest_distance_to_target_string_in_a_circular_array.rb) |
450450
| 2520. Count the Digits That Divide a Number | [Link](https://leetcode.com/problems/count-the-digits-that-divide-a-number/) | [Link](./lib/easy/2520_count_the_digits_that_divide_a_number.rb) |
451451
| 2525. Categorize Box According to Criteria | [Link](https://leetcode.com/problems/categorize-box-according-to-criteria/) | [Link](./lib/easy/2525_categorize_box_according_to_criteria.rb) |
452+
| 2529. Maximum Count of Positive Integer and Negative Integer | [Link](https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/) | [Link](./lib/easy/2529_maximum_count_of_positive_integer_and_negative_integer.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 = '5.8.8'
8+
s.version = '5.8.9'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
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/maximum-count-of-positive-integer-and-negative-integer/
4+
# @param {Integer[]} nums
5+
# @return {Integer}
6+
def maximum_count(nums)
7+
positive = 0
8+
negative = 0
9+
nums.each do |num|
10+
if num.positive?
11+
positive += 1
12+
elsif num.negative?
13+
negative += 1
14+
end
15+
end
16+
17+
[positive, negative].max
18+
end
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2529_maximum_count_of_positive_integer_and_negative_integer'
5+
require 'minitest/autorun'
6+
7+
class MaximumCountOfPositiveIntegerAndNegativeIntegerTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(3, maximum_count([-2, -1, -1, 1, 2, 3]))
10+
assert_equal(3, maximum_count([-3, -2, -1, 0, 0, 1, 2]))
11+
assert_equal(4, maximum_count([5, 20, 66, 1314]))
12+
end
13+
end

0 commit comments

Comments
 (0)