Skip to content

2025-03-24 v. 9.0.9: added "2177. Find Three Consecutive Integers That Sum to a Given Number" #998

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 @@ -743,6 +743,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 2150. Find All Lonely Numbers in the Array | [Link](https://leetcode.com/problems/find-all-lonely-numbers-in-the-array/) | [Link](./lib/medium/2150_find_all_lonely_numbers_in_the_array.rb) | [Link](./test/medium/test_2150_find_all_lonely_numbers_in_the_array.rb) |
| 2161. Partition Array According to Given Pivot | [Link](https://leetcode.com/problems/partition-array-according-to-given-pivot/) | [Link](./lib/medium/2161_partition_array_according_to_given_pivot.rb) | [Link](./test/medium/test_2161_partition_array_according_to_given_pivot.rb) |
| 2165. Smallest Value of the Rearranged Number | [Link](https://leetcode.com/problems/smallest-value-of-the-rearranged-number/) | [Link](./lib/medium/2165_smallest_value_of_the_rearranged_number.rb) | [Link](./test/medium/test_2165_smallest_value_of_the_rearranged_number.rb) |
| 2177. Find Three Consecutive Integers That Sum to a Given Number | [Link](https://leetcode.com/problems/find-three-consecutive-integers-that-sum-to-a-given-number/) | [Link](./lib/medium/2177_find_three_consecutive_integers_that_sum_to_a_given_number.rb) | [Link](./test/medium/test_2177_find_three_consecutive_integers_that_sum_to_a_given_number.rb) |
| 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) |
| 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) |
| 2657. Find the Prefix Common Array of Two Arrays | [Link](https://leetcode.com/problems/find-the-prefix-common-array-of-two-arrays/) | [Link](./lib/medium/2657_find_the_prefix_common_array_of_two_arrays.rb) | [Link](./test/medium/test_2657_find_the_prefix_common_array_of_two_arrays.rb) |
Expand Down
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 = '9.0.8'
s.version = '9.0.9'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
s.executable = 'leetcode-ruby'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

# https://leetcode.com/problems/find-three-consecutive-integers-that-sum-to-a-given-number/
# @param {Integer} num
# @return {Integer[]}
def sum_of_three(num)
middle = num / 3
start = middle - 1
nd = middle + 1

return [] unless (start + middle + nd) == num

[start, middle, nd]
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require_relative '../test_helper'
require_relative '../../lib/medium/2177_find_three_consecutive_integers_that_sum_to_a_given_number'
require 'minitest/autorun'

class FindThreeConsecutiveIntegersThatSumToAGivenNumberTest < ::Minitest::Test
def test_default_one
assert_equal(
[10, 11, 12],
sum_of_three(33)
)
end

def test_default_two
assert_equal(
[],
sum_of_three(4)
)
end
end