Skip to content

Commit c28dbd6

Browse files
authored
chore: format rust code with rustfmt (doocs#3140)
1 parent a463351 commit c28dbd6

File tree

474 files changed

+14354
-14729
lines changed

Some content is hidden

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

474 files changed

+14354
-14729
lines changed

basic/sorting/HeapSort/README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -480,19 +480,13 @@ fn sink(nums: &mut Vec<i32>, mut i: usize, n: usize) {
480480
fn main() -> io::Result<()> {
481481
let mut s = String::new();
482482
io::stdin().read_line(&mut s)?;
483-
let s: Vec<usize> = s
484-
.split(' ')
485-
.map(|s| s.trim().parse().unwrap())
486-
.collect();
483+
let s: Vec<usize> = s.split(' ').map(|s| s.trim().parse().unwrap()).collect();
487484
// let n = s[0];
488485
let m = s[1];
489486

490487
let mut nums = String::new();
491488
io::stdin().read_line(&mut nums)?;
492-
let mut nums: Vec<i32> = nums
493-
.split(' ')
494-
.map(|s| s.trim().parse().unwrap())
495-
.collect();
489+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
496490

497491
heap_sort(&mut nums);
498492
for num in nums.iter().take(m) {

basic/sorting/MergeSort/README.md

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

303303
let mut nums = String::new();
304304
io::stdin().read_line(&mut nums)?;
305-
let mut nums: Vec<i32> = nums
306-
.split(' ')
307-
.map(|s| s.trim().parse().unwrap())
308-
.collect();
305+
let mut nums: Vec<i32> = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect();
309306

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

lcci/01.03.String to URL/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,11 @@ impl Solution {
181181
s.chars()
182182
.take(length as usize)
183183
.map(|c| {
184-
if c == ' ' { "%20".to_string() } else { c.to_string() }
184+
if c == ' ' {
185+
"%20".to_string()
186+
} else {
187+
c.to_string()
188+
}
185189
})
186190
.collect()
187191
}

lcci/01.03.String to URL/README_EN.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,11 @@ impl Solution {
195195
s.chars()
196196
.take(length as usize)
197197
.map(|c| {
198-
if c == ' ' { "%20".to_string() } else { c.to_string() }
198+
if c == ' ' {
199+
"%20".to_string()
200+
} else {
201+
c.to_string()
202+
}
199203
})
200204
.collect()
201205
}

lcci/02.05.Sum Lists/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul
220220
impl Solution {
221221
pub fn add_two_numbers(
222222
mut l1: Option<Box<ListNode>>,
223-
mut l2: Option<Box<ListNode>>
223+
mut l2: Option<Box<ListNode>>,
224224
) -> Option<Box<ListNode>> {
225225
let mut dummy = Some(Box::new(ListNode::new(0)));
226226
let mut cur = dummy.as_mut();

lcci/02.05.Sum Lists/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ function addTwoNumbers(l1: ListNode | null, l2: ListNode | null): ListNode | nul
224224
impl Solution {
225225
pub fn add_two_numbers(
226226
mut l1: Option<Box<ListNode>>,
227-
mut l2: Option<Box<ListNode>>
227+
mut l2: Option<Box<ListNode>>,
228228
) -> Option<Box<ListNode>> {
229229
let mut dummy = Some(Box::new(ListNode::new(0)));
230230
let mut cur = dummy.as_mut();

lcci/03.02.Min Stack/README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,10 @@ struct MinStack {
250250
impl MinStack {
251251
/** initialize your data structure here. */
252252
fn new() -> Self {
253-
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
253+
Self {
254+
stack: VecDeque::new(),
255+
min_stack: VecDeque::new(),
256+
}
254257
}
255258

256259
fn push(&mut self, x: i32) {

lcci/03.02.Min Stack/README_EN.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,10 @@ struct MinStack {
270270
impl MinStack {
271271
/** initialize your data structure here. */
272272
fn new() -> Self {
273-
Self { stack: VecDeque::new(), min_stack: VecDeque::new() }
273+
Self {
274+
stack: VecDeque::new(),
275+
min_stack: VecDeque::new(),
276+
}
274277
}
275278

276279
fn push(&mut self, x: i32) {

lcci/03.05.Sort of Stacks/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,11 @@ impl SortedStack {
323323
}
324324

325325
fn peek(&self) -> i32 {
326-
if self.is_empty() { -1 } else { *self.stk.back().unwrap() }
326+
if self.is_empty() {
327+
-1
328+
} else {
329+
*self.stk.back().unwrap()
330+
}
327331
}
328332

329333
fn is_empty(&self) -> bool {

lcci/03.05.Sort of Stacks/README_EN.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,11 @@ impl SortedStack {
337337
}
338338

339339
fn peek(&self) -> i32 {
340-
if self.is_empty() { -1 } else { *self.stk.back().unwrap() }
340+
if self.is_empty() {
341+
-1
342+
} else {
343+
*self.stk.back().unwrap()
344+
}
341345
}
342346

343347
fn is_empty(&self) -> bool {

lcci/03.06.Animal Shelter/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,8 @@ impl AnimalShelf {
304304
}
305305

306306
fn dequeue_any(&mut self) -> Vec<i32> {
307-
if
308-
self.q[0].is_empty() ||
309-
(!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap())
307+
if self.q[0].is_empty()
308+
|| (!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap())
310309
{
311310
self.dequeue_dog()
312311
} else {

lcci/03.06.Animal Shelter/README_EN.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -318,9 +318,8 @@ impl AnimalShelf {
318318
}
319319

320320
fn dequeue_any(&mut self) -> Vec<i32> {
321-
if
322-
self.q[0].is_empty() ||
323-
(!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap())
321+
if self.q[0].is_empty()
322+
|| (!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap())
324323
{
325324
self.dequeue_dog()
326325
} else {

lcci/04.02.Minimum Height Tree/README.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -190,23 +190,19 @@ function sortedArrayToBST(nums: number[]): TreeNode | null {
190190
// }
191191
// }
192192
// }
193-
use std::rc::Rc;
194193
use std::cell::RefCell;
194+
use std::rc::Rc;
195195
impl Solution {
196196
fn dfs(nums: &Vec<i32>, l: usize, r: usize) -> Option<Rc<RefCell<TreeNode>>> {
197197
if l >= r {
198198
return None;
199199
}
200200
let mid = (l + r) >> 1;
201-
Some(
202-
Rc::new(
203-
RefCell::new(TreeNode {
204-
val: nums[mid],
205-
left: Self::dfs(nums, l, mid),
206-
right: Self::dfs(nums, mid + 1, r),
207-
})
208-
)
209-
)
201+
Some(Rc::new(RefCell::new(TreeNode {
202+
val: nums[mid],
203+
left: Self::dfs(nums, l, mid),
204+
right: Self::dfs(nums, mid + 1, r),
205+
})))
210206
}
211207
pub fn sorted_array_to_bst(nums: Vec<i32>) -> Option<Rc<RefCell<TreeNode>>> {
212208
Self::dfs(&nums, 0, nums.len())

lcci/04.02.Minimum Height Tree/README_EN.md

+6-10
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,19 @@ function sortedArrayToBST(nums: number[]): TreeNode | null {
214214
// }
215215
// }
216216
// }
217-
use std::rc::Rc;
218217
use std::cell::RefCell;
218+
use std::rc::Rc;
219219
impl Solution {
220220
fn dfs(nums: &Vec<i32>, l: usize, r: usize) -> Option<Rc<RefCell<TreeNode>>> {
221221
if l >= r {
222222
return None;
223223
}
224224
let mid = (l + r) >> 1;
225-
Some(
226-
Rc::new(
227-
RefCell::new(TreeNode {
228-
val: nums[mid],
229-
left: Self::dfs(nums, l, mid),
230-
right: Self::dfs(nums, mid + 1, r),
231-
})
232-
)
233-
)
225+
Some(Rc::new(RefCell::new(TreeNode {
226+
val: nums[mid],
227+
left: Self::dfs(nums, l, mid),
228+
right: Self::dfs(nums, mid + 1, r),
229+
})))
234230
}
235231
pub fn sorted_array_to_bst(nums: Vec<i32>) -> Option<Rc<RefCell<TreeNode>>> {
236232
Self::dfs(&nums, 0, nums.len())

lcci/04.03.List of Depth/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ function listOfDepth(tree: TreeNode | null): Array<ListNode | null> {
301301
// }
302302
// }
303303
// }
304-
use std::rc::Rc;
305304
use std::cell::RefCell;
306305
use std::collections::VecDeque;
306+
use std::rc::Rc;
307307
impl Solution {
308308
pub fn list_of_depth(tree: Option<Rc<RefCell<TreeNode>>>) -> Vec<Option<Box<ListNode>>> {
309309
let mut res = vec![];

lcci/04.03.List of Depth/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,9 @@ function listOfDepth(tree: TreeNode | null): Array<ListNode | null> {
314314
// }
315315
// }
316316
// }
317-
use std::rc::Rc;
318317
use std::cell::RefCell;
319318
use std::collections::VecDeque;
319+
use std::rc::Rc;
320320
impl Solution {
321321
pub fn list_of_depth(tree: Option<Rc<RefCell<TreeNode>>>) -> Vec<Option<Box<ListNode>>> {
322322
let mut res = vec![];

lcci/04.05.Legal Binary Search Tree/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ function isValidBST(root: TreeNode | null): boolean {
223223
// }
224224
// }
225225
// }
226-
use std::rc::Rc;
227226
use std::cell::RefCell;
227+
use std::rc::Rc;
228228
impl Solution {
229229
fn dfs(root: &Option<Rc<RefCell<TreeNode>>>, prev: &mut Option<i32>) -> bool {
230230
if root.is_none() {

lcci/04.05.Legal Binary Search Tree/README_EN.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,8 @@ function isValidBST(root: TreeNode | null): boolean {
261261
// }
262262
// }
263263
// }
264-
use std::rc::Rc;
265264
use std::cell::RefCell;
265+
use std::rc::Rc;
266266
impl Solution {
267267
fn dfs(root: &Option<Rc<RefCell<TreeNode>>>, prev: &mut Option<i32>) -> bool {
268268
if root.is_none() {

lcci/04.10.Check SubTree/README.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -256,17 +256,17 @@ function checkSubTree(t1: TreeNode | null, t2: TreeNode | null): boolean {
256256
// }
257257
// }
258258
// }
259-
use std::rc::Rc;
260259
use std::cell::RefCell;
260+
use std::rc::Rc;
261261
impl Solution {
262262
fn dfs(t1: &Option<Rc<RefCell<TreeNode>>>, t2: &Option<Rc<RefCell<TreeNode>>>) -> bool {
263263
match (t1, t2) {
264264
(Some(node1), Some(node2)) => {
265265
let n1 = node1.borrow();
266266
let n2 = node2.borrow();
267-
n1.val == n2.val &&
268-
Solution::dfs(&n1.left, &n2.left) &&
269-
Solution::dfs(&n1.right, &n2.right)
267+
n1.val == n2.val
268+
&& Solution::dfs(&n1.left, &n2.left)
269+
&& Solution::dfs(&n1.right, &n2.right)
270270
}
271271
(None, Some(_)) => false,
272272
(Some(_), None) => false,
@@ -276,15 +276,15 @@ impl Solution {
276276

277277
pub fn check_sub_tree(
278278
t1: Option<Rc<RefCell<TreeNode>>>,
279-
t2: Option<Rc<RefCell<TreeNode>>>
279+
t2: Option<Rc<RefCell<TreeNode>>>,
280280
) -> bool {
281281
match (t1, t2) {
282282
(Some(node1), Some(node2)) => {
283283
let n1 = node1.borrow();
284284
let n2 = node2.borrow();
285-
Solution::dfs(&Some(Rc::clone(&node1)), &Some(Rc::clone(&node2))) ||
286-
Solution::check_sub_tree(n1.left.clone(), Some(Rc::clone(&node2))) ||
287-
Solution::check_sub_tree(n1.right.clone(), Some(Rc::clone(&node2)))
285+
Solution::dfs(&Some(Rc::clone(&node1)), &Some(Rc::clone(&node2)))
286+
|| Solution::check_sub_tree(n1.left.clone(), Some(Rc::clone(&node2)))
287+
|| Solution::check_sub_tree(n1.right.clone(), Some(Rc::clone(&node2)))
288288
}
289289
(Some(_), None) => true,
290290
(None, Some(_)) => false,

lcci/04.10.Check SubTree/README_EN.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,17 @@ function checkSubTree(t1: TreeNode | null, t2: TreeNode | null): boolean {
264264
// }
265265
// }
266266
// }
267-
use std::rc::Rc;
268267
use std::cell::RefCell;
268+
use std::rc::Rc;
269269
impl Solution {
270270
fn dfs(t1: &Option<Rc<RefCell<TreeNode>>>, t2: &Option<Rc<RefCell<TreeNode>>>) -> bool {
271271
match (t1, t2) {
272272
(Some(node1), Some(node2)) => {
273273
let n1 = node1.borrow();
274274
let n2 = node2.borrow();
275-
n1.val == n2.val &&
276-
Solution::dfs(&n1.left, &n2.left) &&
277-
Solution::dfs(&n1.right, &n2.right)
275+
n1.val == n2.val
276+
&& Solution::dfs(&n1.left, &n2.left)
277+
&& Solution::dfs(&n1.right, &n2.right)
278278
}
279279
(None, Some(_)) => false,
280280
(Some(_), None) => false,
@@ -284,15 +284,15 @@ impl Solution {
284284

285285
pub fn check_sub_tree(
286286
t1: Option<Rc<RefCell<TreeNode>>>,
287-
t2: Option<Rc<RefCell<TreeNode>>>
287+
t2: Option<Rc<RefCell<TreeNode>>>,
288288
) -> bool {
289289
match (t1, t2) {
290290
(Some(node1), Some(node2)) => {
291291
let n1 = node1.borrow();
292292
let n2 = node2.borrow();
293-
Solution::dfs(&Some(Rc::clone(&node1)), &Some(Rc::clone(&node2))) ||
294-
Solution::check_sub_tree(n1.left.clone(), Some(Rc::clone(&node2))) ||
295-
Solution::check_sub_tree(n1.right.clone(), Some(Rc::clone(&node2)))
293+
Solution::dfs(&Some(Rc::clone(&node1)), &Some(Rc::clone(&node2)))
294+
|| Solution::check_sub_tree(n1.left.clone(), Some(Rc::clone(&node2)))
295+
|| Solution::check_sub_tree(n1.right.clone(), Some(Rc::clone(&node2)))
296296
}
297297
(Some(_), None) => true,
298298
(None, Some(_)) => false,

lcci/04.12.Paths with Sum/README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -251,9 +251,9 @@ function pathSum(root: TreeNode | null, sum: number): number {
251251
// }
252252
// }
253253
// }
254-
use std::rc::Rc;
255254
use std::cell::RefCell;
256255
use std::collections::HashMap;
256+
use std::rc::Rc;
257257
impl Solution {
258258
pub fn path_sum(root: Option<Rc<RefCell<TreeNode>>>, sum: i32) -> i32 {
259259
let mut cnt = HashMap::new();
@@ -265,7 +265,7 @@ impl Solution {
265265
root: Option<Rc<RefCell<TreeNode>>>,
266266
sum: i32,
267267
s: i32,
268-
cnt: &mut HashMap<i32, i32>
268+
cnt: &mut HashMap<i32, i32>,
269269
) -> i32 {
270270
if let Some(node) = root {
271271
let node = node.borrow();

lcci/04.12.Paths with Sum/README_EN.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ function pathSum(root: TreeNode | null, sum: number): number {
264264
// }
265265
// }
266266
// }
267-
use std::rc::Rc;
268267
use std::cell::RefCell;
269268
use std::collections::HashMap;
269+
use std::rc::Rc;
270270
impl Solution {
271271
pub fn path_sum(root: Option<Rc<RefCell<TreeNode>>>, sum: i32) -> i32 {
272272
let mut cnt = HashMap::new();
@@ -278,7 +278,7 @@ impl Solution {
278278
root: Option<Rc<RefCell<TreeNode>>>,
279279
sum: i32,
280280
s: i32,
281-
cnt: &mut HashMap<i32, i32>
281+
cnt: &mut HashMap<i32, i32>,
282282
) -> i32 {
283283
if let Some(node) = root {
284284
let node = node.borrow();

lcci/08.02.Robot in a Grid/README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,9 @@ impl Solution {
186186
}
187187
path.push(vec![i as i32, j as i32]);
188188
grid[i as usize][j as usize] = 1;
189-
if
190-
(i + 1 == grid.len() && j + 1 == grid[0].len()) ||
191-
Self::dfs(grid, path, i + 1, j) ||
192-
Self::dfs(grid, path, i, j + 1)
189+
if (i + 1 == grid.len() && j + 1 == grid[0].len())
190+
|| Self::dfs(grid, path, i + 1, j)
191+
|| Self::dfs(grid, path, i, j + 1)
193192
{
194193
return true;
195194
}

0 commit comments

Comments
 (0)