Skip to content

Commit 3ff0422

Browse files
committed
more setup + first problem
1 parent df50571 commit 3ff0422

File tree

10 files changed

+140
-60
lines changed

10 files changed

+140
-60
lines changed

.ruby-gemset

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
leetcode

.ruby-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.2.2

Gemfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ source "https://rubygems.org"
55
# Specify your gem's dependencies in leetcode.gemspec
66
gemspec
77

8-
gem "rake", "~> 13.0"
9-
10-
gem "rspec", "~> 3.0"
11-
12-
gem "rubocop", "~> 1.21"
8+
group :development do
9+
gem "rake", "~> 13.0"
10+
gem "rspec", "~> 3.0"
11+
gem "rubocop", "~> 1.21"
12+
gem 'sord'
13+
end

Gemfile.lock

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
PATH
2+
remote: .
3+
specs:
4+
leetcode (0.0.1)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
abbrev (0.1.1)
10+
ast (2.4.2)
11+
commander (4.6.0)
12+
highline (~> 2.0.0)
13+
diff-lcs (1.5.0)
14+
highline (2.0.3)
15+
json (2.7.1)
16+
language_server-protocol (3.17.0.3)
17+
parallel (1.23.0)
18+
parlour (5.0.0)
19+
commander (~> 4.5)
20+
parser
21+
rainbow (~> 3.0)
22+
sorbet-runtime (>= 0.5)
23+
parser (3.2.2.4)
24+
ast (~> 2.4.1)
25+
racc
26+
racc (1.7.3)
27+
rainbow (3.1.1)
28+
rake (13.1.0)
29+
rbs (3.3.2)
30+
abbrev
31+
regexp_parser (2.8.3)
32+
rexml (3.2.6)
33+
rspec (3.12.0)
34+
rspec-core (~> 3.12.0)
35+
rspec-expectations (~> 3.12.0)
36+
rspec-mocks (~> 3.12.0)
37+
rspec-core (3.12.2)
38+
rspec-support (~> 3.12.0)
39+
rspec-expectations (3.12.3)
40+
diff-lcs (>= 1.2.0, < 2.0)
41+
rspec-support (~> 3.12.0)
42+
rspec-mocks (3.12.6)
43+
diff-lcs (>= 1.2.0, < 2.0)
44+
rspec-support (~> 3.12.0)
45+
rspec-support (3.12.1)
46+
rubocop (1.58.0)
47+
json (~> 2.3)
48+
language_server-protocol (>= 3.17.0)
49+
parallel (~> 1.10)
50+
parser (>= 3.2.2.4)
51+
rainbow (>= 2.2.2, < 4.0)
52+
regexp_parser (>= 1.8, < 3.0)
53+
rexml (>= 3.2.5, < 4.0)
54+
rubocop-ast (>= 1.30.0, < 2.0)
55+
ruby-progressbar (~> 1.7)
56+
unicode-display_width (>= 2.4.0, < 3.0)
57+
rubocop-ast (1.30.0)
58+
parser (>= 3.2.1.0)
59+
ruby-progressbar (1.13.0)
60+
sorbet-runtime (0.5.11147)
61+
sord (6.0.0)
62+
commander (~> 4.5)
63+
parlour (~> 5.0)
64+
rbs (~> 3.0)
65+
sorbet-runtime
66+
yard
67+
unicode-display_width (2.5.0)
68+
yard (0.9.34)
69+
70+
PLATFORMS
71+
x86_64-linux
72+
73+
DEPENDENCIES
74+
leetcode!
75+
rake (~> 13.0)
76+
rspec (~> 3.0)
77+
rubocop (~> 1.21)
78+
sord
79+
80+
BUNDLED WITH
81+
2.4.10

README.md

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,2 @@
11
# Leetcode
2-
3-
TODO: Delete this and the text below, and describe your gem
4-
5-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/leetcode`. To experiment with that code, run `bin/console` for an interactive prompt.
6-
7-
## Installation
8-
9-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10-
11-
Install the gem and add to the application's Gemfile by executing:
12-
13-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
14-
15-
If bundler is not being used to manage dependencies, install the gem by executing:
16-
17-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
18-
19-
## Usage
20-
21-
TODO: Write usage instructions here
22-
23-
## Development
24-
25-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26-
27-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
28-
29-
## Contributing
30-
31-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/leetcode. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/leetcode/blob/master/CODE_OF_CONDUCT.md).
32-
33-
## Code of Conduct
34-
35-
Everyone interacting in the Leetcode project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/leetcode/blob/master/CODE_OF_CONDUCT.md).
2+
Leetcode problems + solutions

leetcode.gemspec

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
11
# frozen_string_literal: true
22

3-
require_relative "lib/leetcode/version"
4-
53
Gem::Specification.new do |spec|
64
spec.name = "leetcode"
7-
spec.version = Leetcode::VERSION
5+
spec.version = '0.0.1'
86
spec.authors = ["Xero"]
97
spec.email = ["[email protected]"]
108

11-
spec.summary = "TODO: Write a short summary, because RubyGems requires one."
12-
spec.description = "TODO: Write a longer description or delete this line."
13-
spec.homepage = "TODO: Put your gem's website or public repo URL here."
14-
spec.required_ruby_version = ">= 2.6.0"
15-
16-
spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
9+
spec.summary = "Leetcode problems and solutions."
10+
spec.homepage = "https://github.com/one-m1nd/leetcode"
11+
spec.required_ruby_version = ">= 3.0.0"
1712

1813
spec.metadata["homepage_uri"] = spec.homepage
19-
spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
20-
spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
2114

2215
# Specify which files should be added to the gem when it is released.
2316
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.

lib/leetcode.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# frozen_string_literal: true
22

3-
require_relative "leetcode/version"
3+
require 'leetcode/median_of_two_sorted_arrays'
44

55
module Leetcode
6-
class Error < StandardError; end
7-
# Your code goes here...
86
end
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module Leetcode
2+
class MedianOfTwoSortedArrays
3+
# @param nums1 [Array<Integer>]
4+
# @param nums2 [Array<Integer>]
5+
# @return [Float]
6+
def execute(nums1, nums2)
7+
nums = (nums1 + nums2).sort
8+
half = (nums.length/2).floor
9+
10+
if nums.length.even?
11+
(nums[half] + nums[half - 1]) / 2.0
12+
else
13+
nums[half].to_f
14+
end
15+
end
16+
end
17+
end
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
RSpec.describe Leetcode::MedianOfTwoSortedArrays do
2+
describe '#execute' do
3+
let(:nums1) { [] }
4+
let(:nums2) { [] }
5+
6+
subject { Leetcode::MedianOfTwoSortedArrays.new.execute(nums1, nums2) }
7+
8+
context '[1, 3], [2]' do
9+
let(:nums1) { [1, 3] }
10+
let(:nums2) { [2] }
11+
12+
it do
13+
expect(subject).to be_instance_of(Float)
14+
expect(subject).to eql(2.0)
15+
end
16+
end
17+
18+
context '[1, 2], [3, 4]' do
19+
let(:nums1) { [1, 2] }
20+
let(:nums2) { [3, 4] }
21+
22+
it do
23+
expect(subject).to be_instance_of(Float)
24+
expect(subject).to eql(2.5)
25+
end
26+
end
27+
end
28+
end

spec/leetcode_spec.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
11
# frozen_string_literal: true
22

33
RSpec.describe Leetcode do
4-
it "has a version number" do
5-
expect(Leetcode::VERSION).not_to be nil
6-
end
7-
8-
it "does something useful" do
9-
expect(false).to eq(true)
10-
end
114
end

0 commit comments

Comments
 (0)