Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ff17a65

Browse files
committed
2025年04月23日 v. 9.3.2: added "2966. Divide Array Into Arrays With Max Difference"
1 parent 25ea315 commit ff17a65

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
455455
| 2549. Count Distinct Numbers on Board | [Link](https://leetcode.com/problems/count-distinct-numbers-on-board/) | [Link](./lib/easy/2549_count_distinct_numbers_on_board.rb) | [Link](./test/easy/test_2549_count_distinct_numbers_on_board.rb) |
456456
| 2652. Sum Multiples | [Link](https://leetcode.com/problems/sum-multiples/) | [Link](./lib/easy/2652_sum_multiples.rb) | [Link](./test/easy/test_2652_sum_multiples.rb) |
457457
| 2951. Find the Peaks | [Link](https://leetcode.com/problems/find-the-peaks/) | [Link](./lib/easy/2951_find_the_peaks.rb) | [Link](./test/easy/test_2951_find_the_peaks.rb) |
458+
| 2966. Divide Array Into Arrays With Max Difference | [Link](https://leetcode.com/problems/divide-array-into-arrays-with-max-difference/) | [Link](./lib/easy/2966_divide_array_into_arrays_with_max_difference.rb) | [Link](./test/easy/test_2966_divide_array_into_arrays_with_max_difference.rb) |
458459
| 2974. Minimum Number Game | [Link](https://leetcode.com/problems/minimum-number-game/) | [Link](./lib/easy/2974_minimum_number_game.rb) | [Link](./test/easy/test_2974_minimum_number_game.rb) |
459460
| 3083. Existence of a Substring in a String and Its Reverse | [Link](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/) | [Link](./lib/easy/3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) | [Link](./test/easy/test_3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) |
460461
| 3090. Maximum Length Substring With Two Occurrences | [Link](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences/) | [Link](./lib/easy/3090_maximum_length_substring_with_two_occurrences.rb) | [Link](./test/easy/test_3090_maximum_length_substring_with_two_occurrences.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 = '9.3.1'
8+
s.version = '9.3.2'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
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/divide-array-into-arrays-with-max-difference/
4+
# @param {Integer[]} nums
5+
# @param {Integer} k
6+
# @return {Integer[][]}
7+
def divide_array2966(nums, k)
8+
nums.sort!
9+
result = []
10+
11+
(0...nums.length).step(3) do |i|
12+
return [] if nums[i + 2] - nums[i] > k
13+
14+
result << [nums[i], nums[i + 1], nums[i + 2]]
15+
end
16+
17+
result
18+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2966_divide_array_into_arrays_with_max_difference'
5+
require 'minitest/autorun'
6+
7+
class DivideArrayIntoArraysWithMaxDifferenceTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
[
11+
[1, 1, 3],
12+
[3, 4, 5],
13+
[7, 8, 9]
14+
],
15+
divide_array2966(
16+
[1, 3, 4, 8, 7, 9, 3, 5, 1],
17+
3
18+
)
19+
)
20+
end
21+
22+
def test_default_two
23+
assert_equal(
24+
[],
25+
divide_array2966(
26+
[2, 4, 2, 2, 5, 2],
27+
2
28+
)
29+
)
30+
end
31+
32+
def test_default_three
33+
assert_equal(
34+
[
35+
[2, 2, 2],
36+
[4, 5, 5],
37+
[5, 5, 7],
38+
[7, 8, 8],
39+
[9, 9, 10],
40+
[11, 12, 12]
41+
],
42+
divide_array2966(
43+
[4, 2, 9, 8, 2, 12, 7, 12, 10, 5, 8, 5, 5, 7, 9, 2, 5, 11],
44+
14
45+
)
46+
)
47+
end
48+
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /