-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #180 from fartem/674_Longest_Continuous_Increasing…
…_Subsequence 2023-01-27 v. 1.3.1: added "674. Longest Continuous Increasing Subsequence"
- Loading branch information
Showing
4 changed files
with
43 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
# https://leetcode.com/problems/longest-continuous-increasing-subsequence/ | ||
# @param {Integer[]} nums | ||
# @return {Integer} | ||
def find_length_of_lcis(nums) | ||
result = 0 | ||
max = 1 | ||
(1...nums.length).step(1) do |i| | ||
if nums[i - 1] < nums[i] | ||
max += 1 | ||
else | ||
result = max if max > result | ||
max = 1 | ||
end | ||
end | ||
|
||
[result, max].max | ||
end |
22 changes: 22 additions & 0 deletions
22
test/easy/test_674_longest_continuous_increasing_subsequence.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# frozen_string_literal: true | ||
|
||
require_relative '../test_helper' | ||
require_relative '../../lib/easy/674_longest_continuous_increasing_subsequence' | ||
require 'minitest/autorun' | ||
|
||
class LongestContinuousIncreasingSubsequenceTest < ::Minitest::Test | ||
def test_default | ||
assert_equal( | ||
3, | ||
find_length_of_lcis( | ||
[1, 3, 5, 4, 7] | ||
) | ||
) | ||
assert_equal( | ||
1, | ||
find_length_of_lcis( | ||
[2, 2, 2, 2, 2] | ||
) | ||
) | ||
end | ||
end |