Skip to content

Commit a463351

Browse files
authored
feat: add rustfmt tool (doocs#3139)
1 parent 2644bd7 commit a463351

File tree

358 files changed

+875
-1757
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

358 files changed

+875
-1757
lines changed

.github/workflows/prettier.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
- name: Run prettier
3030
run: |
3131
git config --global core.quotepath off
32-
changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" | grep -E '\.js$|\.ts$|\.php$|\.sql$|\.rs$|\.md$' || true)
32+
changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" | grep -E '\.js$|\.ts$|\.php$|\.sql$|\.md$' || true)
3333
if [ -n "$changed_files" ]; then
3434
echo "Running prettier on the changed files"
3535
echo "$changed_files" | xargs -d '\n' npx prettier --write

.prettierrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
"options": { "parser": "mysql" }
1818
}
1919
],
20-
"plugins": ["prettier-plugin-rust", "prettier-plugin-sql-cst", "@prettier/plugin-php"]
20+
"plugins": ["prettier-plugin-sql-cst", "@prettier/plugin-php"]
2121
}

basic/sorting/HeapSort/README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,13 @@ fn sink(nums: &mut Vec<i32>, mut i: usize, n: usize) {
207207
fn main() -> io::Result<()> {
208208
let mut s = String::new();
209209
io::stdin().read_line(&mut s)?;
210-
let s: Vec<usize> = s
211-
.split(' ')
212-
.map(|s| s.trim().parse().unwrap())
213-
.collect();
210+
let s: Vec<usize> = s.split(' ').map(|s| s.trim().parse().unwrap()).collect();
214211
// let n = s[0];
215212
let m = s[1];
216213

217214
let mut nums = String::new();
218215
io::stdin().read_line(&mut nums)?;
219-
let mut nums: Vec<i32> = nums
220-
.split(' ')
221-
.map(|s| s.trim().parse().unwrap())
222-
.collect();
216+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
223217

224218
heap_sort(&mut nums);
225219
for num in nums.iter().take(m) {

basic/sorting/HeapSort/Solution.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,13 @@ fn sink(nums: &mut Vec<i32>, mut i: usize, n: usize) {
3737
fn main() -> io::Result<()> {
3838
let mut s = String::new();
3939
io::stdin().read_line(&mut s)?;
40-
let s: Vec<usize> = s
41-
.split(' ')
42-
.map(|s| s.trim().parse().unwrap())
43-
.collect();
40+
let s: Vec<usize> = s.split(' ').map(|s| s.trim().parse().unwrap()).collect();
4441
// let n = s[0];
4542
let m = s[1];
4643

4744
let mut nums = String::new();
4845
io::stdin().read_line(&mut nums)?;
49-
let mut nums: Vec<i32> = nums
50-
.split(' ')
51-
.map(|s| s.trim().parse().unwrap())
52-
.collect();
46+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
5347

5448
heap_sort(&mut nums);
5549
for num in nums.iter().take(m) {

basic/sorting/MergeSort/Main.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ fn main() -> io::Result<()> {
4343

4444
let mut nums = String::new();
4545
io::stdin().read_line(&mut nums)?;
46-
let mut nums: Vec<i32> = nums
47-
.split(' ')
48-
.map(|s| s.trim().parse().unwrap())
49-
.collect();
46+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
5047

5148
merge_sort(&mut nums, 0, n - 1);
5249
for num in nums.iter() {

basic/sorting/MergeSort/Solution.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,7 @@ fn main() -> io::Result<()> {
4343

4444
let mut nums = String::new();
4545
io::stdin().read_line(&mut nums)?;
46-
let mut nums: Vec<i32> = nums
47-
.split(' ')
48-
.map(|s| s.trim().parse().unwrap())
49-
.collect();
46+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
5047

5148
merge_sort(&mut nums, 0, n - 1);
5249
for num in nums.iter() {

basic/sorting/QuickSort/Main.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ fn main() -> io::Result<()> {
3737

3838
let mut nums = String::new();
3939
io::stdin().read_line(&mut nums)?;
40-
let mut nums: Vec<i32> = nums
41-
.split(' ')
42-
.map(|s| s.trim().parse().unwrap())
43-
.collect();
40+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
4441

4542
quick_sort(&mut nums, 0, n - 1);
4643
for num in nums.iter() {

basic/sorting/QuickSort/README.md

+1-4
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,7 @@ fn main() -> io::Result<()> {
267267

268268
let mut nums = String::new();
269269
io::stdin().read_line(&mut nums)?;
270-
let mut nums: Vec<i32> = nums
271-
.split(' ')
272-
.map(|s| s.trim().parse().unwrap())
273-
.collect();
270+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
274271

275272
quick_sort(&mut nums, 0, n - 1);
276273
for num in nums.iter() {

basic/sorting/QuickSort/Solution.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ fn main() -> io::Result<()> {
3737

3838
let mut nums = String::new();
3939
io::stdin().read_line(&mut nums)?;
40-
let mut nums: Vec<i32> = nums
41-
.split(' ')
42-
.map(|s| s.trim().parse().unwrap())
43-
.collect();
40+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
4441

4542
quick_sort(&mut nums, 0, n - 1);
4643
for num in nums.iter() {

lcci/01.03.String to URL/Solution2.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ impl Solution {
33
s.chars()
44
.take(length as usize)
55
.map(|c| {
6-
if c == ' ' { "%20".to_string() } else { c.to_string() }
6+
if c == ' ' {
7+
"%20".to_string()
8+
} else {
9+
c.to_string()
10+
}
711
})
812
.collect()
913
}

lcci/02.05.Sum Lists/Solution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
impl Solution {
22
pub fn add_two_numbers(
33
mut l1: Option<Box<ListNode>>,
4-
mut l2: Option<Box<ListNode>>
4+
mut l2: Option<Box<ListNode>>,
55
) -> Option<Box<ListNode>> {
66
let mut dummy = Some(Box::new(ListNode::new(0)));
77
let mut cur = dummy.as_mut();

lcci/03.02.Min Stack/README.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,7 @@ impl MinStack {
274274
fn get_min(&self) -> i32 {
275275
*self.min_stack.back().unwrap()
276276
}
277-
}/**
278-
* Your MinStack object will be instantiated and called as such:
279-
* let obj = MinStack::new();
280-
* obj.push(x);
281-
* obj.pop();
282-
* let ret_3: i32 = obj.top();
283-
* let ret_4: i32 = obj.get_min();
284-
*/
277+
}
285278
```
286279

287280
#### C#

lcci/03.02.Min Stack/README_EN.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,7 @@ impl MinStack {
294294
fn get_min(&self) -> i32 {
295295
*self.min_stack.back().unwrap()
296296
}
297-
}/**
298-
* Your MinStack object will be instantiated and called as such:
299-
* let obj = MinStack::new();
300-
* obj.push(x);
301-
* obj.pop();
302-
* let ret_3: i32 = obj.top();
303-
* let ret_4: i32 = obj.get_min();
304-
*/
297+
}
305298
```
306299

307300
#### C#

lcci/03.02.Min Stack/Solution.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ struct MinStack {
1111
impl MinStack {
1212
/** initialize your data structure here. */
1313
fn new() -> Self {
14-
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
14+
Self {
15+
stack: VecDeque::new(),
16+
min_stack: VecDeque::new(),
17+
}
1518
}
1619

1720
fn push(&mut self, x: i32) {
@@ -35,11 +38,4 @@ impl MinStack {
3538
fn get_min(&self) -> i32 {
3639
*self.min_stack.back().unwrap()
3740
}
38-
}/**
39-
* Your MinStack object will be instantiated and called as such:
40-
* let obj = MinStack::new();
41-
* obj.push(x);
42-
* obj.pop();
43-
* let ret_3: i32 = obj.top();
44-
* let ret_4: i32 = obj.get_min();
45-
*/
41+
}

lcci/03.04.Implement Queue using Stacks/README.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,7 @@ impl MyQueue {
314314
}
315315
}
316316
}
317-
}/**
318-
* Your MyQueue object will be instantiated and called as such:
319-
* let obj = MyQueue::new();
320-
* obj.push(x);
321-
* let ret_2: i32 = obj.pop();
322-
* let ret_3: i32 = obj.peek();
323-
* let ret_4: bool = obj.empty();
324-
*/
317+
}
325318
```
326319

327320
#### Swift

lcci/03.04.Implement Queue using Stacks/README_EN.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -346,14 +346,7 @@ impl MyQueue {
346346
}
347347
}
348348
}
349-
}/**
350-
* Your MyQueue object will be instantiated and called as such:
351-
* let obj = MyQueue::new();
352-
* obj.push(x);
353-
* let ret_2: i32 = obj.pop();
354-
* let ret_3: i32 = obj.peek();
355-
* let ret_4: bool = obj.empty();
356-
*/
349+
}
357350
```
358351

359352
#### Swift

lcci/03.04.Implement Queue using Stacks/Solution.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,4 @@ impl MyQueue {
3838
}
3939
}
4040
}
41-
}/**
42-
* Your MyQueue object will be instantiated and called as such:
43-
* let obj = MyQueue::new();
44-
* obj.push(x);
45-
* let ret_2: i32 = obj.pop();
46-
* let ret_3: i32 = obj.peek();
47-
* let ret_4: bool = obj.empty();
48-
*/
41+
}

lcci/03.05.Sort of Stacks/README.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,7 @@ impl SortedStack {
329329
fn is_empty(&self) -> bool {
330330
self.stk.is_empty()
331331
}
332-
}/**
333-
* Your SortedStack object will be instantiated and called as such:
334-
* let obj = SortedStack::new();
335-
* obj.push(val);
336-
* obj.pop();
337-
* let ret_3: i32 = obj.peek();
338-
* let ret_4: bool = obj.is_empty();
339-
*/
332+
}
340333
```
341334

342335
#### Swift

lcci/03.05.Sort of Stacks/README_EN.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,7 @@ impl SortedStack {
343343
fn is_empty(&self) -> bool {
344344
self.stk.is_empty()
345345
}
346-
}/**
347-
* Your SortedStack object will be instantiated and called as such:
348-
* let obj = SortedStack::new();
349-
* obj.push(val);
350-
* obj.pop();
351-
* let ret_3: i32 = obj.peek();
352-
* let ret_4: bool = obj.is_empty();
353-
*/
346+
}
354347
```
355348

356349
#### Swift

lcci/03.05.Sort of Stacks/Solution.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,14 @@ impl SortedStack {
3434
}
3535

3636
fn peek(&self) -> i32 {
37-
if self.is_empty() { -1 } else { *self.stk.back().unwrap() }
37+
if self.is_empty() {
38+
-1
39+
} else {
40+
*self.stk.back().unwrap()
41+
}
3842
}
3943

4044
fn is_empty(&self) -> bool {
4145
self.stk.is_empty()
4246
}
43-
}/**
44-
* Your SortedStack object will be instantiated and called as such:
45-
* let obj = SortedStack::new();
46-
* obj.push(val);
47-
* obj.pop();
48-
* let ret_3: i32 = obj.peek();
49-
* let ret_4: bool = obj.is_empty();
50-
*/
47+
}

lcci/03.06.Animal Shelter/README.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -331,14 +331,7 @@ impl AnimalShelf {
331331
vec![cat, 0]
332332
}
333333
}
334-
}/**
335-
* Your AnimalShelf object will be instantiated and called as such:
336-
* let obj = AnimalShelf::new();
337-
* obj.enqueue(animal);
338-
* let ret_2: Vec<i32> = obj.dequeue_any();
339-
* let ret_3: Vec<i32> = obj.dequeue_dog();
340-
* let ret_4: Vec<i32> = obj.dequeue_cat();
341-
*/
334+
}
342335
```
343336

344337
#### Swift

lcci/03.06.Animal Shelter/README_EN.md

+1-8
Original file line numberDiff line numberDiff line change
@@ -345,14 +345,7 @@ impl AnimalShelf {
345345
vec![cat, 0]
346346
}
347347
}
348-
}/**
349-
* Your AnimalShelf object will be instantiated and called as such:
350-
* let obj = AnimalShelf::new();
351-
* obj.enqueue(animal);
352-
* let ret_2: Vec<i32> = obj.dequeue_any();
353-
* let ret_3: Vec<i32> = obj.dequeue_dog();
354-
* let ret_4: Vec<i32> = obj.dequeue_cat();
355-
*/
348+
}
356349
```
357350

358351
#### Swift

lcci/03.06.Animal Shelter/Solution.rs

+3-11
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ impl AnimalShelf {
1616
}
1717

1818
fn dequeue_any(&mut self) -> Vec<i32> {
19-
if
20-
self.q[0].is_empty() ||
21-
(!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap())
19+
if self.q[0].is_empty()
20+
|| (!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap())
2221
{
2322
self.dequeue_dog()
2423
} else {
@@ -43,11 +42,4 @@ impl AnimalShelf {
4342
vec![cat, 0]
4443
}
4544
}
46-
}/**
47-
* Your AnimalShelf object will be instantiated and called as such:
48-
* let obj = AnimalShelf::new();
49-
* obj.enqueue(animal);
50-
* let ret_2: Vec<i32> = obj.dequeue_any();
51-
* let ret_3: Vec<i32> = obj.dequeue_dog();
52-
* let ret_4: Vec<i32> = obj.dequeue_cat();
53-
*/
45+
}

lcci/04.02.Minimum Height Tree/Solution.rs

+6-10
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,19 @@
1616
// }
1717
// }
1818
// }
19-
use std::rc::Rc;
2019
use std::cell::RefCell;
20+
use std::rc::Rc;
2121
impl Solution {
2222
fn dfs(nums: &Vec<i32>, l: usize, r: usize) -> Option<Rc<RefCell<TreeNode>>> {
2323
if l >= r {
2424
return None;
2525
}
2626
let mid = (l + r) >> 1;
27-
Some(
28-
Rc::new(
29-
RefCell::new(TreeNode {
30-
val: nums[mid],
31-
left: Self::dfs(nums, l, mid),
32-
right: Self::dfs(nums, mid + 1, r),
33-
})
34-
)
35-
)
27+
Some(Rc::new(RefCell::new(TreeNode {
28+
val: nums[mid],
29+
left: Self::dfs(nums, l, mid),
30+
right: Self::dfs(nums, mid + 1, r),
31+
})))
3632
}
3733
pub fn sorted_array_to_bst(nums: Vec<i32>) -> Option<Rc<RefCell<TreeNode>>> {
3834
Self::dfs(&nums, 0, nums.len())

lcci/04.03.List of Depth/Solution.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
// }
3333
// }
3434
// }
35-
use std::rc::Rc;
3635
use std::cell::RefCell;
3736
use std::collections::VecDeque;
37+
use std::rc::Rc;
3838
impl Solution {
3939
pub fn list_of_depth(tree: Option<Rc<RefCell<TreeNode>>>) -> Vec<Option<Box<ListNode>>> {
4040
let mut res = vec![];

0 commit comments

Comments
 (0)