Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 80f105b

Browse files
authored
Merge pull request #1028 from fartem/3386-Button-with-Longest-Push-Time
2025年05月02日 v. 9.3.7: added "3386. Button with Longest Push Time"
2 parents 77fac88 + ba70365 commit 80f105b

File tree

4 files changed

+56
-1
lines changed

4 files changed

+56
-1
lines changed

‎README.md‎

Lines changed: 1 addition & 0 deletions
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

‎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 = '9.3.6'
8+
s.version = '9.3.7'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'
Lines changed: 21 additions & 0 deletions
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
Lines changed: 33 additions & 0 deletions
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)

AltStyle によって変換されたページ (->オリジナル) /