Skip to content

2024-06-14 v. 5.8.9: added "2529. Maximum Count of Positive Integer and Negative Integer" #646

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -449,3 +449,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 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) |
| 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) |
| 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) |
| 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) |
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '5.8.8'
s.version = '5.8.9'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

# https://leetcode.com/problems/maximum-count-of-positive-integer-and-negative-integer/
# @param {Integer[]} nums
# @return {Integer}
def maximum_count(nums)
positive = 0
negative = 0
nums.each do |num|
if num.positive?
positive += 1
elsif num.negative?
negative += 1
end
end

[positive, negative].max
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/easy/2529_maximum_count_of_positive_integer_and_negative_integer'
require 'minitest/autorun'

class MaximumCountOfPositiveIntegerAndNegativeIntegerTest < ::Minitest::Test
def test_default
assert_equal(3, maximum_count([-2, -1, -1, 1, 2, 3]))
assert_equal(3, maximum_count([-3, -2, -1, 0, 0, 1, 2]))
assert_equal(4, maximum_count([5, 20, 66, 1314]))
end
end
Loading