Skip to content

Commit

Permalink
problem set + solution
Browse files Browse the repository at this point in the history
  • Loading branch information
one-m1nd committed Dec 16, 2023
1 parent 152e669 commit 0ae0553
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/leetcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'leetcode/sudoku_solver'
require 'leetcode/longest_valid_parens'
require 'leetcode/merge_k_sorted_lists'
require 'leetcode/first_missing_positive'
require 'leetcode/reverse_nodes_in_k_group'
require 'leetcode/median_of_two_sorted_arrays'
require 'leetcode/regular_expression_matching'
Expand Down
14 changes: 14 additions & 0 deletions lib/leetcode/first_missing_positive.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module Leetcode
# https://leetcode.com/problems/first-missing-positive/
class FirstMissingPositive
def execute(nums)
lowest = 1

nums.each do |num|
lowest += 1 if num == lowest
end

lowest
end
end
end
30 changes: 30 additions & 0 deletions spec/leetcode/first_missing_positive_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
RSpec.describe Leetcode::FirstMissingPositive do
describe '#execute' do
let(:nums) { [] }
subject { Leetcode::FirstMissingPositive.new.execute(nums)}

context '[1,2,0]' do
let(:nums) { [1,2,0] }

it do
expect(subject).to be 3
end
end

context '[3,4,-1,1]' do
let(:nums) { [3,4,-1,1] }

it do
expect(subject).to be 2
end
end

context '[7,8,9,11,12]' do
let(:nums) { [7,8,9,11,12] }

it do
expect(subject).to be 1
end
end
end
end

0 comments on commit 0ae0553

Please sign in to comment.