A tool for showing and counting solutions from LeetCode.
$ gem i lcspBuild and install gem from sources:
$ gem build lcsp.gemspec
$ gem i lcspYou need to provide 3 arguments for run print command:
| Parameter | Description | Example |
|---|---|---|
user |
GitHub user name | fartem |
repo |
Repository name | leetcode-ruby |
number |
Number of problem | 11 |
One of valid input variants be like:
$ lcsp print --user=fartem --repo=leetcode-ruby --number=11You need to provide 2 arguments for run count command:
| Parameter | Description | Example |
|---|---|---|
user |
GitHub user name | fartem |
repo |
Repository name | leetcode-ruby |
One of valid input variants be like:
$ lcsp count --user=fartem --repo=leetcode-rubyJust run next command from any folder:
$ lcsp cleanYou can see actual author contacts by following command:
$ lcsp authorIf you need to check installed version of lcsp, run from shell:
$ lcsp authorlcsp works with custom finders - classes that should placed in your project and that will perform
search locally.
You need to write finder classes in Ruby because only this format accepting right now, but all work around search and parse for your repository you can place in classes/scripts/files in any other programming language.
One of the correct and working example available by this link.
path and number are default parameters that are presenting for every repository. This arguments describes user needs
and gives you parameters to search.
# frozen_string_literal: true
module LCSP
# Solutions finder.
class LCSPFinder
# @param {String} path
# @param {String} number
def initialize(path, number)
@path = path
@number = number
end
# @return {String}
def solution
end
end
end# frozen_string_literal: true
module LCSP
# Solutions finder.
class LCSPFinder
# @param {String} path
# @param {String} number
def initialize(path, number)
@path = path
@number = number
end
# @return {String}
def solution
dirs = []
fill_directories(@path, dirs)
dirs.each do |directory|
::Dir.foreach(directory) do |entry|
return "#{directory}/#{entry}" if entry.start_with?(@number)
end
end
end
# @param {String} path
# @param {String[]} dirs
def fill_directories(path, dirs)
::Dir.foreach(path).reject { |name| name.start_with?('.') }.each do |entry|
unless ::File.file?("#{path}/#{entry}")
dirs << "#{path}/#{entry}"
fill_directories("#{path}/#{entry}", dirs)
end
end
end
end
endlcsc works with custom counters - classes that should placed in your project and that will perform
count locally.
You need to write counter classes in Ruby because only this format accepting right now, but all work around search and parse for your repository you can place in classes/scripts/files in any other programming language.
One of the correct and working example available by this link.
path are default parameter that are presenting for every repository. It is a path to repository in cache.
# frozen_string_literal: true
require 'find'
module LCSC
# Solutions counter.
class LCSCCounter
# @param {String} path
def initialize(path)
@path = path
end
# @return {Integer}
def count
dir_sub = "#{@path}/lib"
easy = find_for_dir("#{dir_sub}/easy")
medium = find_for_dir("#{dir_sub}/medium")
easy + medium
end
private
def find_for_dir(dir)
::Find.find(dir).count { |file| ::File.file?(file) }
end
end
end# frozen_string_literal: true
module LCSC
# Solutions counter.
class LCSCFinder
# @param {String} path
def initialize(path)
@path = path
end
# @return {Integer}
def count
end
end
end- @fartem as Artem Fomchenkov