leetcode

package
v0.1.0-alpha.3 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2023 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	PaidOnlyQuestion = errors.New("this is paid only question, you need to subscribe to LeetCode Premium")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	BaseURI() string
	Login(username, password string) (*http.Response, error)
	GetUserStatus() (*UserStatus, error)
	GetQuestionData(slug string) (*QuestionData, error)
	GetAllQuestions() ([]*QuestionData, error)
	GetTodayQuestion() (*QuestionData, error)
	InterpretSolution(q *QuestionData, lang string, code string, dataInput string) (
		*InterpretSolutionResult,
		error,
	)
	CheckSubmissionResult(submissionId string) (*SubmissionCheckResult, error)
	Submit(q *QuestionData, lang string, code string) (string, error)
}

func NewClient

func NewClient(options ...ClientOption) Client

type ClientOption

type ClientOption func(*Options)

func WithCredentials

func WithCredentials(cred CredentialsProvider) ClientOption

type CodeSnippet

type CodeSnippet struct {
	LangSlug string `json:"langSlug"`
	Lang     string `json:"lang"`
	Code     string `json:"code"`
}

type Contest

type Contest struct {
	TitleSlug string `json:"titleSlug"`
	Title     string `json:"title"`
	StartTime string `json:"startTime"`
	Questions []*QuestionData
}

func ContestBySlug

func ContestBySlug(slug string, c Client) *Contest

type CredentialsProvider

type CredentialsProvider interface {
	AddCredentials(req *http.Request) error
}

func CredentialsFromConfig

func CredentialsFromConfig() CredentialsProvider

func NewBrowserAuth

func NewBrowserAuth(browsers ...string) CredentialsProvider

func NewCookiesAuth

func NewCookiesAuth(session, csrftoken string) CredentialsProvider

func NewPasswordAuth

func NewPasswordAuth(username, passwd string) CredentialsProvider

func NonAuth

func NonAuth() CredentialsProvider

type InterpretSolutionResult

type InterpretSolutionResult struct {
	InterpretExpectedId string `json:"interpret_expected_id"`
	InterpretId         string `json:"interpret_id"`
	TestCase            string `json:"test_case"`
}

type JsonExampleTestCases

type JsonExampleTestCases []string

func (*JsonExampleTestCases) UnmarshalJSON

func (j *JsonExampleTestCases) UnmarshalJSON(data []byte) error

type MetaData

type MetaData struct {
	Name   string          `json:"name"`
	Params []MetaDataParam `json:"params"`
	Return MetaDataReturn  `json:"return"`
	// System design problems related
	SystemDesign bool                `json:"systemdesign"`
	ClassName    string              `json:"classname"`
	Constructor  MetaDataConstructor `json:"constructor"`
	Methods      []MetaDataMethod    `json:"methods"`
	// Unknown fields
	Manual bool `json:"manual"`
}

func (*MetaData) UnmarshalJSON

func (m *MetaData) UnmarshalJSON(data []byte) error

type MetaDataConstructor

type MetaDataConstructor struct {
	Params []MetaDataParam `json:"params"`
}

type MetaDataMethod

type MetaDataMethod struct {
	Name   string          `json:"name"`
	Params []MetaDataParam `json:"params"`
	Return MetaDataReturn  `json:"return"`
}

type MetaDataParam

type MetaDataParam struct {
	Name string `json:"name"`
	Type string `json:"type"`
}

type MetaDataReturn

type MetaDataReturn struct {
	Type    string `json:"type"`
	Size    int    `json:"size"`
	Dealloc bool   `json:"dealloc"`
}

type NeedClient

type NeedClient interface {
	SetClient(c Client)
}

type Options

type Options struct {
	// contains filtered or unexported fields
}

type QuestionData

type QuestionData struct {
	TitleSlug            string               `json:"titleSlug"`
	QuestionId           string               `json:"questionId"`
	QuestionFrontendId   string               `json:"questionFrontendId"`
	CategoryTitle        string               `json:"categoryTitle"`
	Title                string               `json:"title"`
	TranslatedTitle      string               `json:"translatedTitle"`
	Difficulty           string               `json:"difficulty"`
	TopicTags            []TopicTag           `json:"topicTags"`
	IsPaidOnly           bool                 `json:"isPaidOnly"`
	Content              string               `json:"content"`
	TranslatedContent    string               `json:"translatedContent"`
	Status               string               `json:"status"` // "ac", "notac", or null
	Stats                Stats                `json:"stats"`
	Hints                []string             `json:"hints"`
	SimilarQuestions     SimilarQuestions     `json:"similarQuestions"`
	SampleTestCase       string               `json:"sampleTestCase"`
	ExampleTestcases     string               `json:"exampleTestcases"`
	JsonExampleTestcases JsonExampleTestCases `json:"jsonExampleTestcases"`
	MetaData             MetaData             `json:"metaData"`
	CodeSnippets         []CodeSnippet        `json:"codeSnippets"`
	// contains filtered or unexported fields
}

func Question

func Question(s string, c Client) (*QuestionData, error)

func QuestionById

func QuestionById(id string, c Client) (*QuestionData, error)

func QuestionBySlug

func QuestionBySlug(slug string, c Client) (*QuestionData, error)

func (*QuestionData) ContestUrl

func (q *QuestionData) ContestUrl() string

func (*QuestionData) GetCodeSnippet

func (q *QuestionData) GetCodeSnippet(slug string) string

func (*QuestionData) GetContent

func (q *QuestionData) GetContent() string

func (*QuestionData) GetExampleOutputs

func (q *QuestionData) GetExampleOutputs() []string

GetExampleOutputs parses example output from content and translatedContent. We can also get correct example outputs by submitting example inputs to judge server.

func (*QuestionData) GetFormattedContent

func (q *QuestionData) GetFormattedContent() string

func (*QuestionData) GetTitle

func (q *QuestionData) GetTitle() string

func (*QuestionData) IsContest

func (q *QuestionData) IsContest() bool

func (*QuestionData) TagSlugs

func (q *QuestionData) TagSlugs() []string

func (*QuestionData) Url

func (q *QuestionData) Url() string

type QuestionsCache

type QuestionsCache interface {
	GetBySlug(slug string) *questionRecord
	GetById(id string) *questionRecord
	Update(client Client) error
}

func GetCache

func GetCache() QuestionsCache

type ResettableProvider

type ResettableProvider interface {
	Reset()
}

type SimilarQuestion

type SimilarQuestion struct {
	Title           string `json:"title"`
	TitleSlug       string `json:"titleSlug"`
	Difficulty      string `json:"difficulty"`
	TranslatedTitle string `json:"translatedTitle"`
}

type SimilarQuestions

type SimilarQuestions []SimilarQuestion

func (*SimilarQuestions) UnmarshalJSON

func (s *SimilarQuestions) UnmarshalJSON(data []byte) error

type Stats

type Stats struct {
	TotalAccepted      string `json:"totalAccepted"`
	TotalSubmission    string `json:"totalSubmission"`
	TotalAcceptedRaw   int    `json:"totalAcceptedRaw"`
	TotalSubmissionRaw int    `json:"totalSubmissionRaw"`
	ACRate             string `json:"acRate"`
}

func (*Stats) UnmarshalJSON

func (s *Stats) UnmarshalJSON(data []byte) error

type SubmissionCheckResult

type SubmissionCheckResult struct {
	SubmissionId           string   `json:"submission_id"`
	State                  string   `json:"state"`
	StatusCode             int      `json:"status_code"`
	StatusMsg              string   `json:"status_msg"`
	StatusMemory           string   `json:"status_memory"`
	Memory                 int      `json:"memory"`
	MemoryPercentile       int      `json:"memory_percentile"`
	StatusRuntime          string   `json:"status_runtime"`
	RuntimePercentile      int      `json:"runtime_percentile"`
	Lang                   string   `json:"lang"`
	PrettyLang             string   `json:"pretty_lang"`
	CodeAnswer             []string `json:"code_answer"`
	CodeOutput             []string `json:"code_output"`
	CompareResult          string   `json:"compare_result"`
	CorrectAnswer          bool     `json:"correct_answer"`
	StdOutputList          []string `json:"std_output_list"`
	TaskName               string   `json:"task_name"`
	TotalCorrect           int      `json:"total_correct"`
	TotalTestcases         int      `json:"total_testcases"`
	ElapsedTime            int      `json:"elapsed_time"`
	TaskFinishTime         int      `json:"task_finish_time"`
	RunSuccess             bool     `json:"run_success"`
	FastSubmit             bool     `json:"fast_submit"`
	ExpectedCodeAnswer     []string `json:"expected_code_answer"`
	ExpectedCodeOutput     []string `json:"expected_code_output"`
	ExpectedElapsedTime    int      `json:"expected_elapsed_time"`
	ExpectedLang           string   `json:"expected_lang"`
	ExpectedMemory         int      `json:"expected_memory"`
	ExpectedRunSuccess     bool     `json:"expected_run_success"`
	ExpectedStatusCode     int      `json:"expected_status_code"`
	ExpectedStatusRuntime  string   `json:"expected_status_runtime"`
	ExpectedStdOutputList  []string `json:"expected_std_output_list"`
	ExpectedTaskFinishTime int      `json:"expected_task_finish_time"`
	ExpectedTaskName       string   `json:"expected_task_name"`
}

type TopicTag

type TopicTag struct {
	Slug           string `json:"slug"`
	Name           string `json:"name"`
	TranslatedName string `json:"translatedName"`
}

type UserStatus

type UserStatus struct {
	Username        string `json:"username"`
	UserSlug        string `json:"userSlug"`
	RealName        string `json:"realName"`
	Avatar          string `json:"avatar"`
	ActiveSessionId int    `json:"activeSessionId"`
	IsSignedIn      bool   `json:"isSignedIn"`
	IsPremium       bool   `json:"isPremium"`
}

Jump to

Keyboard shortcuts

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