Skip to content

Commit d82b9e7

Browse files
committed
2025-01-14 v. 8.0.0: added "937. Reorder Data in Log Files"
1 parent d60c460 commit d82b9e7

File tree

4 files changed

+99
-1
lines changed

4 files changed

+99
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
642642
| 916. Word Subsets | [Link](https://leetcode.com/problems/word-subsets/) | [Link](./lib/medium/916_word_subsets.rb) | [Link](./test/medium/test_916_word_subsets.rb) |
643643
| 919. Complete Binary Tree Inserter | [Link](https://leetcode.com/problems/complete-binary-tree-inserter/) | [Link](./lib/medium/919_complete_binary_tree_inserter.rb) | [Link](./test/medium/test_919_complete_binary_tree_inserter.rb) |
644644
| 921. Minimum Add to Make Parentheses Valid | [Link](https://leetcode.com/problems/minimum-add-to-make-parentheses-valid/) | [Link](./lib/medium/921_minimum_add_to_make_parentheses_valid.rb) | [Link](./test/medium/test_921_minimum_add_to_make_parentheses_valid.rb) |
645+
| 937. Reorder Data in Log Files | [Link](https://leetcode.com/problems/reorder-data-in-log-files/) | [Link](./lib/medium/937_reorder_data_in_log_files.rb) | [Link](./test/medium/test_937_reorder_data_in_log_files.rb) |
645646
| 1400. Construct K Palindrome Strings | [Link](https://leetcode.com/problems/construct-k-palindrome-strings/) | [Link](./lib/medium/1400_construct_k_palindrome_strings.rb) | [Link](./test/medium/test_1400_construct_k_palindrome_strings.rb) |
646647
| 2116. Check if a Parentheses String Can Be Valid | [Link](https://leetcode.com/problems/check-if-a-parentheses-string-can-be-valid/) | [Link](./lib/medium/2116_check_if_a_parentheses_string_can_be_valid.rb) | [Link](./test/medium/test_2116_check_if_a_parentheses_string_can_be_valid.rb) |
647648
| 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) |

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 = '7.9.9'
8+
s.version = '8.0.0'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/reorder-data-in-log-files/
4+
# @param {String[]} logs
5+
# @return {String[]}
6+
def reorder_log_files(logs)
7+
partitions =
8+
logs.partition do |log|
9+
log = log.split
10+
!('0'..'9').include?(log[1][0])
11+
end
12+
13+
partitions[0].sort! do |p1, p2|
14+
p1_split = p1.split
15+
p2_split = p2.split
16+
17+
if p1_split[1..] == p2_split[1..]
18+
p1_split[0] <=> p2_split[0]
19+
else
20+
p1_split[1..] <=> p2_split[1..]
21+
end
22+
end
23+
24+
partitions.flatten
25+
end
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/937_reorder_data_in_log_files'
5+
require 'minitest/autorun'
6+
7+
class ReorderDataInLogFilesTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
[
11+
'let1 art can',
12+
'let3 art zero',
13+
'let2 own kit dig',
14+
'dig1 8 1 5 1',
15+
'dig2 3 6'
16+
],
17+
reorder_log_files(
18+
[
19+
'dig1 8 1 5 1',
20+
'let1 art can',
21+
'dig2 3 6',
22+
'let2 own kit dig',
23+
'let3 art zero'
24+
]
25+
)
26+
)
27+
end
28+
29+
def test_default_two
30+
assert_equal(
31+
[
32+
'g1 act car',
33+
'a8 act zoo',
34+
'ab1 off key dog',
35+
'a1 9 2 3 1',
36+
'zo4 4 7'
37+
],
38+
reorder_log_files(
39+
[
40+
'a1 9 2 3 1',
41+
'g1 act car',
42+
'zo4 4 7',
43+
'ab1 off key dog',
44+
'a8 act zoo'
45+
]
46+
)
47+
)
48+
end
49+
50+
def test_additional_one
51+
assert_equal(
52+
[
53+
'a2 act car',
54+
'g1 act car',
55+
'a8 act zoo',
56+
'ab1 off key dog',
57+
'a1 9 2 3 1',
58+
'zo4 4 7'
59+
],
60+
reorder_log_files(
61+
[
62+
'a1 9 2 3 1',
63+
'g1 act car',
64+
'zo4 4 7',
65+
'ab1 off key dog',
66+
'a8 act zoo',
67+
'a2 act car'
68+
]
69+
)
70+
)
71+
end
72+
end

0 commit comments

Comments
 (0)