Skip to content

Commit 528cfdb

Browse files
committed
2023-12-15 v. 3.7.5: added "1827. Minimum Operations to Make the Array Increasing"
1 parent 1d2dbc6 commit 528cfdb

6 files changed

+41
-5
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
321321
| 1812. Determine Color of a Chessboard Square | [Link](https://leetcode.com/problems/determine-color-of-a-chessboard-square/) | [Link](./lib/easy/1812_determine_color_of_a_chessboard_square.rb) |
322322
| 1816. Truncate Sentence | [Link](https://leetcode.com/problems/truncate-sentence/) | [Link](./lib/easy/1816_truncate_sentence.rb) |
323323
| 1822. Sign of the Product of an Array | [Link](https://leetcode.com/problems/sign-of-the-product-of-an-array/) | [Link](./lib/easy/1822_sign_of_the_product_of_an_array.rb) |
324+
| 1827. Minimum Operations to Make the Array Increasing | [Link](https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/) | [Link](./lib/easy/1827_minimum_operations_to_make_the_array_increasing.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 = '3.7.4'
8+
s.version = '3.7.5'
99
s.license = 'MIT'
1010
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
1111
s.executable = 'leetcode-ruby'

lib/easy/1598_crawler_log_folder.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# https://leetcode.com/problems/crawler-log-folder/
44
# @param {String[]} logs
55
# @return {Integer}
6-
def min_operations(logs)
6+
def _1598_min_operations(logs)
77
stack = []
88
logs.each do |log|
99
if log == '../'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# frozen_string_literal: true
2+
3+
# https://leetcode.com/problems/minimum-operations-to-make-the-array-increasing/
4+
# @param {Integer[]} nums
5+
# @return {Integer}
6+
def _1827_min_operations(nums)
7+
result = 0
8+
curr = nums.first
9+
(1...nums.length).each do |i|
10+
num = nums[i]
11+
12+
if num <= curr
13+
nxt = curr + 1
14+
result += nxt - num
15+
num = nxt
16+
end
17+
18+
curr = num
19+
end
20+
21+
result
22+
end

test/easy/test_1598_crawler_log_folder.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
class CrawlerLogFolderTest < ::Minitest::Test
88
def test_default
9-
assert_equal(2, min_operations(%w[d1/ d2/ ../ d21/ ./]))
10-
assert_equal(3, min_operations(%w[d1/ d2/ ./ d3/ ../ d31/]))
11-
assert_equal(0, min_operations(%w[d1/ ../ ../ ../]))
9+
assert_equal(2, _1598_min_operations(%w[d1/ d2/ ../ d21/ ./]))
10+
assert_equal(3, _1598_min_operations(%w[d1/ d2/ ./ d3/ ../ d31/]))
11+
assert_equal(0, _1598_min_operations(%w[d1/ ../ ../ ../]))
1212
end
1313
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# frozen_string_literal: true
2+
3+
require_relative '../test_helper'
4+
require_relative '../../lib/easy/1827_minimum_operations_to_make_the_array_increasing'
5+
require 'minitest/autorun'
6+
7+
class MinimumOperationsToMakeTheArrayIncreasingTest < ::Minitest::Test
8+
def test_default
9+
assert_equal(3, _1827_min_operations([1, 1, 1]))
10+
assert_equal(14, _1827_min_operations([1, 5, 2, 4, 1]))
11+
assert_equal(0, _1827_min_operations([8]))
12+
end
13+
end

0 commit comments

Comments
 (0)