Skip to content

Commit 2fe2454

Browse files
authored
2024-12-27 v. 7.5.2: added "729. My Calendar I"
2 parents 4d985e0 + 11d7d0e commit 2fe2454

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,3 +616,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
616616
| 713. Subarray Product Less Than K | [Link](https://leetcode.com/problems/subarray-product-less-than-k/) | [Link](./lib/medium/713_subarray_product_less_than_k.rb) | [Link](./test/medium/test_713_subarray_product_less_than_k.rb) |
617617
| 720. Longest Word in Dictionary | [Link](https://leetcode.com/problems/longest-word-in-dictionary/) | [Link](./lib/medium/720_longest_word_in_dictionary.rb) | [Link](./test/medium/test_720_longest_word_in_dictionary.rb) |
618618
| 725. Split Linked List in Parts | [Link](https://leetcode.com/problems/split-linked-list-in-parts/) | [Link](./lib/medium/725_split_linked_list_in_parts.rb) | [Link](./test/medium/test_725_split_linked_list_in_parts.rb) |
619+
| 729. My Calendar I | [Link](https://leetcode.com/problems/my-calendar-i/) | [Link](./lib/medium/729_my_calendar_i.rb) | [Link](./test/medium/test_729_my_calendar_i.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.5.1.1'
8+
s.version = '7.5.2'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'

lib/medium/729_my_calendar_i.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/my-calendar-i/
4+
class MyCalendar
5+
# Init
6+
def initialize
7+
@calendar = []
8+
end
9+
10+
# @param {Integer} start_time
11+
# @param {Integer} end_time
12+
# @return {Boolean}
13+
def book(start_time, end_time)
14+
@calendar.each { |iv| return false if iv[0] < end_time && iv[1] > start_time }
15+
16+
@calendar << [start_time, end_time]
17+
18+
true
19+
end
20+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/medium/729_my_calendar_i'
5+
require 'minitest/autorun'
6+
7+
class MyCalendarITest < ::Minitest::Test
8+
def test_default_one
9+
my_calendar = ::MyCalendar.new
10+
11+
assert(my_calendar.book(10, 20))
12+
assert(!my_calendar.book(15, 25))
13+
assert(my_calendar.book(20, 30))
14+
end
15+
end

0 commit comments

Comments
 (0)