leetcode

package
v0.0.0-...-74f8117 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 9, 2019 License: MIT Imports: 13 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CodeFunc

type CodeFunc func(path string, lang Lang) (string, error)

CodeFunc is the type of function called for get question's code.

type Config

type Config struct {
	Path   string
	Source string
	Lang   string
}

Config is the config for Repo.

func (Config) Valid

func (cfg Config) Valid() error

Valid check cfg.Path and cfg.Lang.

type Key

type Key func(*Question) error

Key is the type of function. It use ID or TitleSlug to get question info from db.

func KeyID

func KeyID(id int) Key

func KeyTitleSlug

func KeyTitleSlug(slug string) Key

type KeyFunc

type KeyFunc func(path string, info os.FileInfo) (Key, error)

KeyFunc is the type of function to indicate question in Repo. The path argument is the relative path of Repo.path. The info argument is the os.FileInfo for the named path. See also https://golang.org/pkg/path/filepath/#WalkFunc

type Lang

type Lang string

Lang resprents a programming language on leetcode.

const (
	C          Lang = "c"
	Cpp        Lang = "cpp"
	CSharp     Lang = "csharp"
	Java       Lang = "java"
	Kotlin     Lang = "kotlin"
	Scala      Lang = "scala"
	Python     Lang = "python"
	Python3    Lang = "python3"
	Ruby       Lang = "ruby"
	JavaScript Lang = "javascript"
	Swift      Lang = "swift"
	Go         Lang = "golang"
	Rust       Lang = "rust"
)

programming languages supported on leetcode.

func (Lang) Valid

func (l Lang) Valid() bool

Valid check if Lang is supported on leetcode.

type Question

type Question struct {
	ID          int    `db:"id"`
	TitleSlug   string `db:"title_slug"`
	Title       string `db:"title"`
	Content     string `db:"content"`
	Difficulty  string `db:"difficulty"`
	Tags        string `db:"tags"`
	CodeSnippet string `db:"code_snippet"`
	Code        string
	// contains filtered or unexported fields
}

Question resprents a Question in leetcode repo.

func (*Question) Fields

func (q *Question) Fields() []string

Fields returns the string fields of the question. If the question has a error, return nil.

type Repo

type Repo struct {
	KeyFn  KeyFunc
	CodeFn CodeFunc
	// contains filtered or unexported fields
}

Repo represents a repo which store leetcode solution code.

func NewRepo

func NewRepo(cfg Config, codeFn CodeFunc, keyFn KeyFunc) *Repo

NewRepo represents a leetcode repo.

func (*Repo) Close

func (r *Repo) Close() error

Close close the Repo, stop filepath.Walk.

func (*Repo) Question

func (r *Repo) Question(key Key, path string) (*Question, error)

Question returns a Question by key and path in Repo.

func (*Repo) Read

func (r *Repo) Read() ([]string, error)

Read reads fields from questions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL