File tree 4 files changed +65
-1
lines changed
4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -495,3 +495,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
495
495
| 75. Sort Colors | [ Link] ( https://leetcode.com/problems/sort-colors/ ) | [ Link] ( ./lib/medium/75_sort_colors.rb ) |
496
496
| 78. Subsets | [ Link] ( https://leetcode.com/problems/subsets/ ) | [ Link] ( ./lib/medium/78_subsets.rb ) |
497
497
| 82. Remove Duplicates from Sorted List II | [ Link] ( https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ ) | [ Link] ( ./lib/medium/82_remove_duplicates_from_sorted_list_ii.rb ) |
498
+ | 86. Partition List | [ Link] ( https://leetcode.com/problems/partition-list/ ) | [ Link] ( ./lib/medium/86_partition_list.rb ) |
Original file line number Diff line number Diff line change @@ -5,7 +5,7 @@ require 'English'
5
5
::Gem ::Specification . new do |s |
6
6
s . required_ruby_version = '>= 3.0'
7
7
s . name = 'leetcode-ruby'
8
- s . version = '6.2.9 '
8
+ s . version = '6.3.0 '
9
9
s . license = 'MIT'
10
10
s . files = ::Dir [ 'lib/**/*.rb' ] + %w[ README.md ]
11
11
s . executable = 'leetcode-ruby'
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../common/linked_list'
4
+
5
+ # https://leetcode.com/problems/partition-list/
6
+ # @param {ListNode} head
7
+ # @param {Integer} x
8
+ # @return {ListNode}
9
+ def partition ( head , x )
10
+ f = ::ListNode . new
11
+ f_p = f
12
+ s = ::ListNode . new
13
+ s_p = s
14
+
15
+ until head . nil?
16
+ if head . val < x
17
+ f_p . next = ::ListNode . new ( head . val )
18
+ f_p = f_p . next
19
+ else
20
+ s_p . next = ::ListNode . new ( head . val )
21
+ s_p = s_p . next
22
+ end
23
+
24
+ head = head . next
25
+ end
26
+
27
+ f_p &.next = s . next
28
+
29
+ f . next
30
+ end
Original file line number Diff line number Diff line change
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../test_helper'
4
+ require_relative '../../lib/common/linked_list'
5
+ require_relative '../../lib/medium/86_partition_list'
6
+ require 'minitest/autorun'
7
+
8
+ class PartitionListTest < ::Minitest ::Test
9
+ def test_default
10
+ assert (
11
+ ::ListNode . are_equals (
12
+ ::ListNode . from_array (
13
+ [ 1 , 2 , 2 , 4 , 3 , 5 ]
14
+ ) ,
15
+ partition (
16
+ ::ListNode . from_array (
17
+ [ 1 , 4 , 3 , 2 , 5 , 2 ]
18
+ ) ,
19
+ 3
20
+ )
21
+ )
22
+ )
23
+ assert (
24
+ ::ListNode . are_equals (
25
+ ::ListNode . from_array ( [ 1 , 2 ] ) ,
26
+ partition (
27
+ ::ListNode . from_array ( [ 2 , 1 ] ) ,
28
+ 2
29
+ )
30
+ )
31
+ )
32
+ end
33
+ end
You can’t perform that action at this time.
0 commit comments