leetcode_rust/
lib.rs

1//! # LeetCode Solutions in Rust
2//! 
3//! ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/zhongdongy/leetcode_rust/solution_test.yml?label=LeetCode%20Solution%20Tests&logo=github&style=plastic)
4//!
5//! [阅读中文内容](#rust-语言下的力扣解法非官方)
6//! 
7//! Rust documentations see [https://leetcode-rust.zhongdongy.com](https://leetcode-rust.zhongdongy.com) 
8//! or [https://leetcode-rust.pages.dev/](https://leetcode-rust.pages.dev/). 
9//! Additional benchmarks available on 
10//! [https://leetcode-rust.zhongdongy.com/criterion/report/](https://leetcode-rust.zhongdongy.com/criterion/report/index.html)
11//!
12//! Note: all problems descriptions collected from 
13//! [LeetCode website](https://leetcode.com/), [力扣](https://leetcode.cn/) and 
14//! all related credits go to LeetCode, 力扣 and its communities. Authors of 
15//! this repository CANNOT and WILL NOT guarantee the correctness of the 
16//! problem descriptions and solutions.
17//!
18//! ## Documentation
19//!
20//! Run `cargo doc` and find the documentation inside `target/doc/leetcode_rust/` directory.
21//!
22//! ### Build documentations
23//!
24//! This command will empty the `docs/` directory and place newly generated docs
25//! there. The documentations are deployed to Cloudflare Pages. Due to build
26//! environment limitations, the docs must be built before pushing to GitHub (so
27//! Cloudflare directly fetches the contents and build on Pages).
28//!
29//! ```bash
30//! ./docsgen.sh
31//! ```
32//!
33//! ## Test
34//!
35//! Solution tests are located in `tests/problems` directory, and grouped by its
36//! problem numbers. Each problem test group (e.g. `p000_0xxx.rs`) corresponds to a
37//! test case module directory (e.g. `cases/c000_0xx/`). Each problem test has its
38//! own case definitions, to use the test cases, just import and call `use_case()`
39//! function.
40//!
41//! ### Test all solutions
42//!
43//! To run all solution tests, simply run:
44//!
45//! ```bash
46//! cargo test --test solutions # LeetCode problems
47//! cargo test --test solutions_cn # 力扣题库
48//! ```
49//!
50//! ### Run documentation tests
51//!
52//! ```bash
53//! cargo test --doc
54//! ```
55//!
56//! ### Run unit tests
57//!
58//! ```bash
59//! cargo test --lib
60//! ```
61//!
62//! ### Run unit tests and all solutions together
63//!
64//! ```bash
65//! cargo test --tests
66//! ```
67//!
68//! ### Run tests for specific problem
69//!
70//! Suppose you would like to test solution for problem #5, run:
71//!
72//! ```bash
73//! cargo test --test solutions p000_005
74//! ```
75//! 
76//! ---
77//! 
78//! # Rust 语言下的力扣解法(非官方)
79//! 
80//! ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/zhongdongy/leetcode_rust/solution_test_cn.yml?label=力扣解法验证&logo=github&style=plastic)
81//! 
82//! [For English readers](#leetcode-solutions-in-rust)
83//! 
84//! 关于 Crate 提供的各个解法的 Rust 文档,请参阅 [https://leetcode-rust.dongs.xyz/](https://leetcode-rust.dongs.xyz/)。
85//! 部分 Benchmark 记录 (由 Criterion.rs 提供) 请参阅 
86//! [https://leetcode-rust.dongs.xyz/criterion/report/](https://leetcode-rust.dongs.xyz/criterion/report/index.html)
87//! 
88//! 请注意,所有的题目来源于 [LeetCode 网站](https://leetcode.com/)和
89//! [力扣](https://leetcode.cn/)。所有题目的著作权属于上述两个平台及相应的社区。
90//! 作者**不能**也**不会**保证题目描述、解法的正确性。
91//!
92//! ## 文档
93//!
94//! 在项目根目录执行 `cargo doc` 命令,然后访问 `target/doc/leetcode_rust/` 目录可以
95//! 找到生成的最新文档。
96//!
97//! ### 构建文档
98//!
99//! 下述命令将会清空您本地项目目录下的 `docs/` 文件夹,然后将新生成的内容放入其中。由于此文档
100//! 部署在 Cloudflare Pages 服务上,而该服务暂不支持使用 Cargo 构建,所以必须在每次推送
101//! 最新更改到 GitHub 之前执行本地文档构建。
102//!
103//! ```bash
104//! ./docsgen.sh
105//! ```
106//!
107//! ## 解法验证
108//!
109//! 所有的解法验证程序都位于 `tests/problems_cn` 目录下,并按照题目编号进行分组。
110//! 每个问题组(如 `p000_0xx.rs` 代表编号 000 到 099 的题目)对应一个单独的测试用例目录
111//! (如 `cases/c000_0xx/`)。每个问题的验证程序都提供了国际版、国内版两组测试用例,但其中的
112//! 大部分都相同样的。要使用某个问题的测试用例,只需要将其引入,然后调用公有的 `use_case()` 
113//! 函数,它的返回值就是测试用例列表。
114//!
115//! ### 验证所有的问题的解法
116//!
117//! 执行下面的命令来执行所有问题的解法:
118//!
119//! ```bash
120//! cargo test --test solutions # LeetCode 国际版题库
121//! cargo test --test solutions_cn # 力扣题库
122//! ```
123//!
124//! ### 执行文档测试
125//!
126//! ```bash
127//! cargo test --doc
128//! ```
129//!
130//! ### 执行单元测试
131//!
132//! ```bash
133//! cargo test --lib
134//! ```
135//!
136//! ### 同时执行单元测试和验证解法
137//!
138//! ```bash
139//! cargo test --tests
140//! ```
141//!
142//! ### 单独验证某个问题的解法
143//!
144//! 假设您想要验证问题 #5 的解,那么可以执行下面的命令:
145//!
146//! ```bash
147//! cargo test --test solutions p000_005
148//! ```
149 
150////////////////////////////////////////////////////////////////////////////////
151
152pub mod macros;
153pub mod models;
154pub mod common;
155pub mod problems;
156pub mod problems_cn;
157pub mod cases;
158pub mod cases_cn;