Skip to content

Commit 07e3fc3

Browse files
authored
2025-01-15 v. 8.0.9: added "950. Reveal Cards In Increasing Order"
2 parents 0a150f1 + 4ec2d07 commit 07e3fc3

File tree

4 files changed

+45
-1
lines changed

4 files changed

+45
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
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) |
645645
| 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) |
646646
| 946. Validate Stack Sequences | [Link](https://leetcode.com/problems/validate-stack-sequences/) | [Link](./lib/medium/946_validate_stack_sequences.rb) | [Link](./test/medium/test_946_validate_stack_sequences.rb) |
647+
| 950. Reveal Cards In Increasing Order | [Link](https://leetcode.com/problems/reveal-cards-in-increasing-order/) | [Link](./lib/medium/950_reveal_cards_in_increasing_order.rb) | [Link](./test/medium/test_950_reveal_cards_in_increasing_order.rb) |
647648
| 951. Flip Equivalent Binary Trees | [Link](https://leetcode.com/problems/flip-equivalent-binary-trees/) | [Link](./lib/medium/951_flip_equivalent_binary_trees.rb) | [Link](./test/medium/test_951_flip_equivalent_binary_trees.rb) |
648649
| 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) |
649650
| 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) |

leetcode-ruby.gemspec

+1-1
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 = '8.0.8'
8+
s.version = '8.0.9'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/reveal-cards-in-increasing-order/
4+
# @param {Integer[]} deck
5+
# @return {Integer[]}
6+
def deck_revealed_increasing(deck)
7+
length = deck.size
8+
indices = (0...length).to_a
9+
deck.sort!
10+
result = ::Array.new(length)
11+
12+
deck.each do |card|
13+
result[indices.shift] = card
14+
indices << indices.shift unless indices.empty?
15+
end
16+
17+
result
18+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/950_reveal_cards_in_increasing_order'
5+
require 'minitest/autorun'
6+
7+
class RevealCardsInIncreasingOrderTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
[2, 13, 3, 11, 5, 17, 7],
11+
deck_revealed_increasing(
12+
[17, 13, 11, 2, 3, 5, 7]
13+
)
14+
)
15+
end
16+
17+
def test_default_two
18+
assert_equal(
19+
[1, 1000],
20+
deck_revealed_increasing(
21+
[1, 1000]
22+
)
23+
)
24+
end
25+
end

0 commit comments

Comments
 (0)