Skip to content

Commit 5694907

Browse files
committed
2024-02-16 v. 4.8.5: added "2073. Time Needed to Buy Tickets"
1 parent 9801a7c commit 5694907

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
366366
| 2057. Smallest Index With Equal Value | [Link](https://leetcode.com/problems/smallest-index-with-equal-value/) | [Link](./lib/easy/2057_smallest_index_with_equal_value.rb) |
367367
| 2062. Count Vowel Substrings of a String | [Link](https://leetcode.com/problems/count-vowel-substrings-of-a-string/) | [Link](./lib/easy/2062_count_vowel_substrings_of_a_string.rb) |
368368
| 2068. Check Whether Two Strings are Almost Equivalent | [Link](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/) | [Link](./lib/easy/2068_check_whether_two_strings_are_almost_equivalent.rb) |
369+
| 2073. Time Needed to Buy Tickets | [Link](https://leetcode.com/problems/time-needed-to-buy-tickets/) | [Link](./lib/easy/2073_time_needed_to_buy_tickets.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 = '4.8.4'
8+
s.version = '4.8.5'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/time-needed-to-buy-tickets/
4+
# @param {Integer[]} tickets
5+
# @param {Integer} k
6+
# @return {Integer}
7+
def time_required_to_buy(tickets, k)
8+
result = 0
9+
(0...tickets.length).each do |i|
10+
n = tickets[k]
11+
c = tickets[i]
12+
13+
result += [i > k ? n - 1 : n, c].min
14+
end
15+
16+
result
17+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2073_time_needed_to_buy_tickets'
5+
require 'minitest/autorun'
6+
7+
class TimeNeededToBuyTicketsTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(6, time_required_to_buy([2, 3, 2], 2))
10+
assert_equal(8, time_required_to_buy([5, 1, 1, 1], 0))
11+
end
12+
end

0 commit comments

Comments
 (0)