Skip to content

Commit 851e4e5

Browse files
authored
Merge branch 'master' into lcsc-3
2 parents 0200fb2 + 80f105b commit 851e4e5

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
466466
| 3151. Special Array I | [Link](https://leetcode.com/problems/special-array-i/) | [Link](./lib/easy/3151_special_array_i.rb) | [Link](./test/easy/test_3151_special_array_i.rb) |
467467
| 3210. Find the Encrypted String | [Link](https://leetcode.com/problems/find-the-encrypted-string/) | [Link](./lib/easy/3210_find_the_encrypted_string.rb) | [Link](./test/easy/test_3210_find_the_encrypted_string.rb) |
468468
| 3280. Convert Date to Binary | [Link](https://leetcode.com/problems/convert-date-to-binary/) | [Link](./lib/easy/3280_convert_date_to_binary.rb) | [Link](./test/easy/test_3280_convert_date_to_binary.rb) |
469+
| 3386. Button with Longest Push Time | [Link](https://leetcode.com/problems/button-with-longest-push-time/) | [Link](./lib/easy/3386_button_with_longest_push_time.rb) | [Link](./test/easy/test_3386_button_with_longest_push_time.rb) |
469470
| 3498. Reverse Degree of a String | [Link](https://leetcode.com/problems/reverse-degree-of-a-string/) | [Link](./lib/easy/3498_reverse_degree_of_a_string.rb) | [Link](./test/easy/test_3498_reverse_degree_of_a_string.rb) |
470471
| 3516. Find Closest Person | [Link](https://leetcode.com/problems/find-closest-person/) | [Link](./lib/easy/3516_find_closest_person.rb) | [Link](./test/easy/test_3516_find_closest_person.rb) |
471472

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/button-with-longest-push-time/
4+
# @param {Integer[][]} events
5+
# @return {Integer}
6+
def button_with_longest_time(events)
7+
max_time = events[0][1]
8+
result = events[0][0]
9+
10+
(1...events.size).each do |i|
11+
press_time = events[i][1] - events[i - 1][1]
12+
13+
next unless press_time > max_time || press_time == max_time && events[i][0] < result
14+
15+
max_time = press_time
16+
17+
result = events[i][0]
18+
end
19+
20+
result
21+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/3386_button_with_longest_push_time'
5+
require 'minitest/autorun'
6+
7+
class ButtonWithLongestPushTimeTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
1,
11+
button_with_longest_time(
12+
[
13+
[1, 2],
14+
[2, 5],
15+
[3, 9],
16+
[1, 15]
17+
]
18+
)
19+
)
20+
end
21+
22+
def test_default_two
23+
assert_equal(
24+
10,
25+
button_with_longest_time(
26+
[
27+
[10, 5],
28+
[1, 7]
29+
]
30+
)
31+
)
32+
end
33+
end

0 commit comments

Comments
 (0)