diff --git a/README.md b/README.md index c02d930e..f1f3666e 100644 --- a/README.md +++ b/README.md @@ -616,3 +616,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/). | 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) | | 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) | | 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) | +| 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) | diff --git a/leetcode-ruby.gemspec b/leetcode-ruby.gemspec index 882b5463..9eb0a6b0 100644 --- a/leetcode-ruby.gemspec +++ b/leetcode-ruby.gemspec @@ -5,7 +5,7 @@ require 'English' ::Gem::Specification.new do |s| s.required_ruby_version = '>= 3.0' s.name = 'leetcode-ruby' - s.version = '7.5.1.1' + s.version = '7.5.2' s.license = 'MIT' s.files = ::Dir['lib/**/*.rb'] + %w[README.md] s.executable = 'leetcode-ruby' diff --git a/lib/medium/729_my_calendar_i.rb b/lib/medium/729_my_calendar_i.rb new file mode 100644 index 00000000..0778634d --- /dev/null +++ b/lib/medium/729_my_calendar_i.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +# https://leetcode.com/problems/my-calendar-i/ +class MyCalendar + # Init + def initialize + @calendar = [] + end + + # @param {Integer} start_time + # @param {Integer} end_time + # @return {Boolean} + def book(start_time, end_time) + @calendar.each { |iv| return false if iv[0] < end_time && iv[1] > start_time } + + @calendar << [start_time, end_time] + + true + end +end diff --git a/test/medium/test_729_my_calendar_i.rb b/test/medium/test_729_my_calendar_i.rb new file mode 100644 index 00000000..95f99d37 --- /dev/null +++ b/test/medium/test_729_my_calendar_i.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require_relative '../test_helper' +require_relative '../../lib/medium/729_my_calendar_i' +require 'minitest/autorun' + +class MyCalendarITest < ::Minitest::Test + def test_default_one + my_calendar = ::MyCalendar.new + + assert(my_calendar.book(10, 20)) + assert(!my_calendar.book(15, 25)) + assert(my_calendar.book(20, 30)) + end +end