Skip to content

Commit 9f4165f

Browse files
committed
fmt file
1 parent dc9e558 commit 9f4165f

File tree

70 files changed

+400
-265
lines changed

Some content is hidden

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

70 files changed

+400
-265
lines changed

src/bin/3sum-closest.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ impl Solution {
1414
if s == target {
1515
return s;
1616
}
17-
sum = if (sum - target).abs() > (s - target).abs() { s } else { sum };
17+
sum = if (sum - target).abs() > (s - target).abs() {
18+
s
19+
} else {
20+
sum
21+
};
1822
}
1923
}
2024
}
@@ -46,7 +50,11 @@ impl Solution {
4650
left += 1;
4751
}
4852

49-
sum = if (s - target).abs() > (sum - target).abs() { sum } else { s };
53+
sum = if (s - target).abs() > (sum - target).abs() {
54+
sum
55+
} else {
56+
s
57+
};
5058
}
5159
}
5260

src/bin/4sum.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ fn main() {
22
// println!("{:?}", Solution::four_sum(vec![1, 0, -1, 0, -2, 2], 0));
33
// println!("{:?}", Solution::four_sum(vec![0, 0, 0, 0], 0));
44
// println!("{:?}", Solution::four_sum(vec![-2, -1, -1, 1, 1, 2, 2], 0));
5-
println!("{:?}", Solution::four_sum(vec![1, -2, -5, -4, -3, 3, 3, 5], -11));
5+
println!(
6+
"{:?}",
7+
Solution::four_sum(vec![1, -2, -5, -4, -3, 3, 3, 5], -11)
8+
);
69
}
710

811
struct Solution;

src/bin/add-binary.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ impl Solution {
2525
b'0'
2626
};
2727

28-
2928
m = Self::add(a1, b1, m.1);
3029
let l = s.len() - index - 1;
3130
s[l] = m.0;
@@ -37,7 +36,10 @@ impl Solution {
3736
s[l] = b'1';
3837
}
3938

40-
String::from_utf8(s).unwrap().trim_start_matches('0').to_string()
39+
String::from_utf8(s)
40+
.unwrap()
41+
.trim_start_matches('0')
42+
.to_string()
4143
}
4244

4345
/// 返回a+b的和与进制

src/bin/add-two-numbers.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,24 @@ pub struct ListNode {
1212
impl ListNode {
1313
#[inline]
1414
fn new(val: i32) -> Self {
15-
ListNode {
16-
next: None,
17-
val,
18-
}
15+
ListNode { next: None, val }
1916
}
2017
}
2118

2219
impl Solution {
23-
pub fn add_two_numbers(l1: Option<Box<ListNode>>, l2: Option<Box<ListNode>>) -> Option<Box<ListNode>> {
20+
pub fn add_two_numbers(
21+
l1: Option<Box<ListNode>>,
22+
l2: Option<Box<ListNode>>,
23+
) -> Option<Box<ListNode>> {
2424
Self::re(l1, l2, 0)
2525
}
2626

27-
2827
/// base: 进制,相加和大于10进制
29-
fn re(l1: Option<Box<ListNode>>, l2: Option<Box<ListNode>>, base: i32) -> Option<Box<ListNode>> {
28+
fn re(
29+
l1: Option<Box<ListNode>>,
30+
l2: Option<Box<ListNode>>,
31+
base: i32,
32+
) -> Option<Box<ListNode>> {
3033
if l1.is_none() && l2.is_none() {
3134
if base == 0 {
3235
return None;

src/bin/balanced-binary-tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ impl TreeNode {
2121
}
2222
}
2323

24-
use std::rc::Rc;
2524
use std::cell::RefCell;
25+
use std::rc::Rc;
2626

2727
impl Solution {
2828
pub fn is_balanced(root: Option<Rc<RefCell<TreeNode>>>) -> bool {

src/bin/binary-search-tree-iterator.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ impl TreeNode {
2121
}
2222
}
2323

24-
use std::rc::Rc;
2524
use std::cell::RefCell;
25+
use std::rc::Rc;
2626

2727
/**
2828
* Your BSTIterator object will be instantiated and called as such:
@@ -31,10 +31,9 @@ use std::cell::RefCell;
3131
* let ret_2: bool = obj.has_next();
3232
*/
3333
struct BSTIterator {
34-
stack: Vec::<Option<Rc<RefCell<TreeNode>>>>
34+
stack: Vec<Option<Rc<RefCell<TreeNode>>>>,
3535
}
3636

37-
3837
/**
3938
* `&self` means the method takes an immutable reference.
4039
* If you need a mutable reference, change it to `&mut self` instead.

src/bin/binary-tree-inorder-traversal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ impl TreeNode {
2121
}
2222
}
2323

24-
use std::rc::Rc;
2524
use std::cell::RefCell;
25+
use std::rc::Rc;
2626

2727
impl Solution {
2828
pub fn inorder_traversal(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {

src/bin/binary-tree-level-order-traversal-ii.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ impl TreeNode {
2121
}
2222
}
2323

24-
use std::rc::Rc;
2524
use std::cell::RefCell;
25+
use std::rc::Rc;
2626

2727
impl Solution {
2828
pub fn level_order_bottom(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<Vec<i32>> {
@@ -36,7 +36,6 @@ impl Solution {
3636
fn f(nodes: Vec<Rc<RefCell<TreeNode>>>) -> Vec<Vec<i32>> {
3737
let mut result = vec![];
3838

39-
4039
if nodes.len() == 0 {
4140
return result;
4241
}

src/bin/binary-tree-level-order-traversal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ impl TreeNode {
2121
}
2222
}
2323

24-
use std::rc::Rc;
2524
use std::cell::RefCell;
25+
use std::rc::Rc;
2626

2727
impl Solution {
2828
pub fn level_order(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<Vec<i32>> {

src/bin/binary-tree-postorder-traversal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ impl TreeNode {
2121
}
2222
}
2323

24-
use std::rc::Rc;
2524
use std::cell::RefCell;
25+
use std::rc::Rc;
2626

2727
impl Solution {
2828
pub fn postorder_traversal(root: Option<Rc<RefCell<TreeNode>>>) -> Vec<i32> {

0 commit comments

Comments
 (0)