Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A full-featured Leetcode API on Rust language

License

NotificationsYou must be signed in to change notification settings

1101-1/Leetcode-Rust-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This Rust library provides a convenient way to interact with the LeetCode API, allowing you to programmatically access LeetCode problems, submit solutions, and retrieve submission results.

Features

  • Retrieve a list of LeetCode problems.
  • Fetch problem details, including the problem description, constraints, and examples.
  • Submit solutions to LeetCode problems.
  • Check submission results, including status, runtime, and memory usage.

Installation

Add the following line to yourCargo.toml file:

[dependencies]leetcode-api ="0.1.2"

Usage

Authentication

To use the LeetCode API, you need to obtain an authentication token. Follow the instructions provided by LeetCode to obtain your token.

Example

use leetcoderustapi::UserApi;#[tokio::main]asyncfnmain(){// Set cookie from leetcodelet token = std::env::var("COOKIE").expect("cookie doesn't set");// Create a new LeetCode clientlet api =UserApi::new(&token).await.unwrap();// Show found problems by keyword and show 5 noteslet show_problems = api.show_tasks_list("sum",5).await.unwrap();// Find problems by properties with creating builderlet show_problems_builder = api.show_task_builder().set_category(leetcoderustapi::Category::Algorithms).set_difficulty(leetcoderustapi::Difficulty::Easy).set_keyword("sum")//max show notes limit is 2763; default is 5.set_note_limit(3).set_status(leetcoderustapi::Status::Solved)//max tags over 50+.set_tags(vec![            leetcoderustapi::Tags::Array,            leetcoderustapi::Tags::BinarySearch,]).build().await.unwrap();// Fetch the full data for a specific problemlet problem_info = api.set_task("two sum").await.unwrap();// Retrieve code snippetslet code_snippets = problem_info.code_snippets();// Retrieve solution infolet solution_info = problem_info.solution_info();// Retrieve related topicslet related_topics = problem_info.related_topics();// Retrieve similar questionslet similar_questions = problem_info.similar_questions();// Retrieve statslet stats = problem_info.stats();// Retrieve hintslet hints = problem_info.hints();// Retrieve descriptionlet description = problem_info.description();// Retrieve difficultylet difficulty = problem_info.difficulty();// Retrieve likeslet likes = problem_info.likes();// Retrieve categorylet category = problem_info.category();// We also can send submissions and tests// Need to specify a lang and provided codelet subm_response = problem_info.send_subm("rust","impl Solution { fn two_sum() {}}").await.unwrap();let test_response = problem_info.send_test("rust","impl Solution { fn two_sum() {}}").await.unwrap();}

That is what is it looks like:

work

Important

Replace"COOKIE" with your actual LeetCode authentication cookie.

For example format in.env file:

COOKIE="csrftoken=gN3mmFEKoBFHLZuiHEvZYupqirq7brDmi845GhUK8xBa9u3SUVkgTPFTPsLFuAzR; _ga_CDRWKZTDEX=GS1.1.1688568040.1.1.1688568081.19.0.0; _ga=GA1.1.2048740381.1688568040; _dd_s=rum=0&expire=1688568980299; NEW_PROBLEMLIST_PAGE=1"

License

This library is licensed under theMIT License.

About

A full-featured Leetcode API on Rust language

Topics

Resources

License

Stars

Watchers

Forks

Languages


[8]ページ先頭

©2009-2025 Movatter.jp