Skip to content

Commit

Permalink
Merge pull request #180 from fartem/674_Longest_Continuous_Increasing…
Browse files Browse the repository at this point in the history
…_Subsequence

2023-01-27 v. 1.3.1: added "674. Longest Continuous Increasing Subsequence"
  • Loading branch information
fartem authored Jul 27, 2023
2 parents 32acba2 + 1837e57 commit fe125d3
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,3 +136,4 @@ Profile on LeetCode: [fartem](https://leetcode.com/fartem/).
| 653. Two Sum IV - Input is a BST | [Link](https://leetcode.com/problems/two-sum-iv-input-is-a-bst/) | [Link](./lib/easy/653_two_sum_iv_input_is_a_bst.rb) |
| 657. Robot Return to Origin | [Link](https://leetcode.com/problems/robot-return-to-origin/) | [Link](./lib/easy/657_robot_return_to_origin.rb) |
| 671. Second Minimum Node In a Binary Tree | [Link](https://leetcode.com/problems/second-minimum-node-in-a-binary-tree/) | [Link](./lib/easy/671_second_minimum_node_in_a_binary_tree.rb) |
| 674. Longest Continuous Increasing Subsequence | [Link](https://leetcode.com/problems/longest-continuous-increasing-subsequence/) | [Link](./lib/easy/674_longest_continuous_increasing_subsequence.rb) |
2 changes: 1 addition & 1 deletion leetcode-ruby.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ require 'English'
::Gem::Specification.new do |s|
s.required_ruby_version = '>= 3.0'
s.name = 'leetcode-ruby'
s.version = '1.3.0'
s.version = '1.3.1'
s.license = 'MIT'
s.files = ::Dir['lib/**/*.rb'] + %w[bin/leetcode-ruby README.md LICENSE]
s.executable = 'leetcode-ruby'
Expand Down
19 changes: 19 additions & 0 deletions lib/easy/674_longest_continuous_increasing_subsequence.rb
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 test/easy/test_674_longest_continuous_increasing_subsequence.rb
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

0 comments on commit fe125d3

Please sign in to comment.