Skip to content

Commit 25ea315

Browse files
authored
2025-04-22 v. 9.3.1: added "2951. Find the Peaks"
2 parents c2ff9e6 + 7bfac76 commit 25ea315

File tree

4 files changed

+41
-1
lines changed

4 files changed

+41
-1
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
454454
| 2544. Alternating Digit Sum | [Link](https://leetcode.com/problems/alternating-digit-sum/) | [Link](./lib/easy/2544_alternating_digit_sum.rb) | [Link](./test/easy/test_2544_alternating_digit_sum.rb) |
455455
| 2549. Count Distinct Numbers on Board | [Link](https://leetcode.com/problems/count-distinct-numbers-on-board/) | [Link](./lib/easy/2549_count_distinct_numbers_on_board.rb) | [Link](./test/easy/test_2549_count_distinct_numbers_on_board.rb) |
456456
| 2652. Sum Multiples | [Link](https://leetcode.com/problems/sum-multiples/) | [Link](./lib/easy/2652_sum_multiples.rb) | [Link](./test/easy/test_2652_sum_multiples.rb) |
457+
| 2951. Find the Peaks | [Link](https://leetcode.com/problems/find-the-peaks/) | [Link](./lib/easy/2951_find_the_peaks.rb) | [Link](./test/easy/test_2951_find_the_peaks.rb) |
457458
| 2974. Minimum Number Game | [Link](https://leetcode.com/problems/minimum-number-game/) | [Link](./lib/easy/2974_minimum_number_game.rb) | [Link](./test/easy/test_2974_minimum_number_game.rb) |
458459
| 3083. Existence of a Substring in a String and Its Reverse | [Link](https://leetcode.com/problems/existence-of-a-substring-in-a-string-and-its-reverse/) | [Link](./lib/easy/3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) | [Link](./test/easy/test_3083_existence_of_a_substring_in_a_string_and_its_reverse.rb) |
459460
| 3090. Maximum Length Substring With Two Occurrences | [Link](https://leetcode.com/problems/maximum-length-substring-with-two-occurrences/) | [Link](./lib/easy/3090_maximum_length_substring_with_two_occurrences.rb) | [Link](./test/easy/test_3090_maximum_length_substring_with_two_occurrences.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 = '9.3.0'
8+
s.version = '9.3.1'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[README.md]
1111
s.executable = 'leetcode-ruby'

lib/easy/2951_find_the_peaks.rb

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/find-the-peaks/
4+
# @param {Integer[]} mountain
5+
# @return {Integer[]}
6+
def find_peaks(mountain)
7+
result = []
8+
9+
(1...mountain.size - 1).each do |i|
10+
result << i if mountain[i] > mountain[i - 1] && mountain[i] > mountain[i + 1]
11+
end
12+
13+
result
14+
end

test/easy/test_2951_find_the_peaks.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/2951_find_the_peaks'
5+
require 'minitest/autorun'
6+
7+
class FindThePeaksTest < ::Minitest::Test
8+
def test_default_one
9+
assert_equal(
10+
[],
11+
find_peaks(
12+
[2, 4, 4]
13+
)
14+
)
15+
end
16+
17+
def test_default_two
18+
assert_equal(
19+
[1, 3],
20+
find_peaks(
21+
[1, 4, 3, 8, 5]
22+
)
23+
)
24+
end
25+
end

0 commit comments

Comments
 (0)