From 0aa6bf99612d4ec17be3e453ad4851ba417b88ee Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Fri, 21 Jun 2024 01:45:44 +0000 Subject: [PATCH] feat: add rustfmt tool --- .github/workflows/prettier.yml | 2 +- .prettierrc | 2 +- basic/sorting/HeapSort/README.md | 10 +--- basic/sorting/HeapSort/Solution.rs | 10 +--- basic/sorting/MergeSort/Main.rs | 5 +- basic/sorting/MergeSort/Solution.rs | 5 +- basic/sorting/QuickSort/Main.rs | 5 +- basic/sorting/QuickSort/README.md | 5 +- basic/sorting/QuickSort/Solution.rs | 5 +- lcci/01.03.String to URL/Solution2.rs | 6 +- lcci/02.05.Sum Lists/Solution.rs | 2 +- lcci/03.02.Min Stack/README.md | 9 +-- lcci/03.02.Min Stack/README_EN.md | 9 +-- lcci/03.02.Min Stack/Solution.rs | 14 ++--- .../README.md | 9 +-- .../README_EN.md | 9 +-- .../Solution.rs | 9 +-- lcci/03.05.Sort of Stacks/README.md | 9 +-- lcci/03.05.Sort of Stacks/README_EN.md | 9 +-- lcci/03.05.Sort of Stacks/Solution.rs | 15 ++--- lcci/03.06.Animal Shelter/README.md | 9 +-- lcci/03.06.Animal Shelter/README_EN.md | 9 +-- lcci/03.06.Animal Shelter/Solution.rs | 14 +---- lcci/04.02.Minimum Height Tree/Solution.rs | 16 ++---- lcci/04.03.List of Depth/Solution.rs | 2 +- .../Solution.rs | 2 +- lcci/04.10.Check SubTree/Solution.rs | 16 +++--- lcci/04.12.Paths with Sum/Solution.rs | 4 +- lcci/08.02.Robot in a Grid/Solution.rs | 7 +-- lcci/10.02.Group Anagrams/Solution.rs | 4 +- lcci/16.02.Words Frequency/README.md | 6 +- lcci/16.02.Words Frequency/README_EN.md | 6 +- lcci/16.02.Words Frequency/Solution.rs | 6 +- lcci/16.25.LRU Cache/README.md | 7 +-- lcci/16.25.LRU Cache/README_EN.md | 7 +-- lcci/16.25.LRU Cache/Solution.rs | 7 +-- .../Solution.rs" | 21 +++---- .../README.md" | 7 +-- .../Solution.rs" | 7 +-- .../Solution.rs" | 11 ++-- .../Solution.rs" | 2 +- .../Solution2.rs" | 2 +- .../Solution.rs" | 12 ++-- .../Solution.rs" | 2 +- .../Solution.rs" | 8 +-- .../README.md" | 9 +-- .../Solution.rs" | 14 ++--- .../Solution.rs" | 2 +- .../Solution.rs" | 2 +- .../Solution.rs" | 2 +- .../Solution.rs" | 6 +- .../Solution.rs" | 4 +- .../README.md" | 7 +-- .../Solution.rs" | 7 +-- .../Solution.rs" | 4 +- .../Solution.rs" | 2 +- .../Solution.rs" | 2 +- .../Solution.rs" | 8 +-- .../README.md" | 8 +-- .../Solution.rs" | 8 +-- .../Solution.rs" | 7 ++- .../Solution.rs" | 4 +- .../Solution.rs" | 8 +-- .../README.md" | 7 +-- .../Solution.rs" | 7 +-- .../Solution.rs" | 6 +- .../Solution.rs" | 2 +- .../Solution.rs" | 16 ++---- .../Solution.rs" | 2 +- .../README.md" | 7 +-- .../Solution.rs" | 13 +---- .../Solution.rs" | 5 +- package-lock.json | 55 +++++-------------- package.json | 6 +- run_format.py | 5 +- .../0002.Add Two Numbers/Solution.rs | 2 +- .../Solution.rs | 3 +- .../0007.Reverse Integer/Solution.rs | 9 ++- .../Solution.rs | 17 ++++-- .../0012.Integer to Roman/Solution.rs | 4 +- .../0013.Roman to Integer/Solution.rs | 14 ++++- .../0014.Longest Common Prefix/Solution.rs | 6 +- .../0021.Merge Two Sorted Lists/Solution.rs | 2 +- .../0021.Merge Two Sorted Lists/Solution2.rs | 2 +- .../Solution.rs | 22 ++------ .../0041.First Missing Positive/Solution.rs | 13 ++--- .../0000-0099/0049.Group Anagrams/Solution.rs | 4 +- .../0000-0099/0065.Valid Number/Solution.rs | 11 ++-- .../0000-0099/0079.Word Search/Solution.rs | 9 +-- .../0092.Reverse Linked List II/Solution.rs | 2 +- .../Solution.rs | 2 +- .../Solution2.rs | 2 +- .../Solution.rs | 18 ++---- .../0097.Interleaving String/Solution.rs | 13 ++--- .../Solution.rs | 2 +- solution/0100-0199/0100.Same Tree/Solution.rs | 4 +- .../0100-0199/0100.Same Tree/Solution2.rs | 4 +- .../0100-0199/0101.Symmetric Tree/Solution.rs | 8 +-- .../0101.Symmetric Tree/Solution2.rs | 2 +- .../Solution.rs | 4 +- .../Solution.rs | 2 +- .../Solution.rs | 2 +- .../Solution.rs | 4 +- .../Solution.rs | 4 +- .../Solution.rs | 2 +- .../Solution.rs | 16 ++---- .../Solution.rs | 16 ++---- .../0110.Balanced Binary Tree/Solution.rs | 2 +- .../Solution.rs | 2 +- solution/0100-0199/0112.Path Sum/Solution.rs | 6 +- .../0100-0199/0113.Path Sum II/Solution.rs | 4 +- .../Solution.rs | 4 +- .../Solution.rs | 2 +- .../0129.Sum Root to Leaf Numbers/Solution.rs | 2 +- .../0130.Surrounded Regions/Solution.rs | 4 +- .../0100-0199/0136.Single Number/Solution.rs | 4 +- .../0137.Single Number II/Solution.rs | 5 +- .../0100-0199/0143.Reorder List/Solution.rs | 6 +- .../Solution.rs | 2 +- .../Solution.rs | 2 +- solution/0100-0199/0146.LRU Cache/README.md | 7 +-- .../0100-0199/0146.LRU Cache/README_EN.md | 7 +-- solution/0100-0199/0146.LRU Cache/Solution.rs | 7 +-- solution/0100-0199/0155.Min Stack/README.md | 9 +-- .../0100-0199/0155.Min Stack/README_EN.md | 9 +-- solution/0100-0199/0155.Min Stack/Solution.rs | 14 ++--- .../README.md | 14 +---- .../README_EN.md | 14 +---- .../Solution.rs | 14 +---- .../Solution2.rs | 11 +--- .../Solution.rs | 2 +- .../0200.Number of Islands/Solution.rs | 11 ++-- .../0200.Number of Islands/Solution2.rs | 11 ++-- .../Solution.rs | 6 +- .../0216.Combination Sum III/Solution.rs | 12 +++- .../Solution.rs | 6 +- .../0226.Invert Binary Tree/Solution.rs | 2 +- .../Solution.rs | 2 +- .../README.md | 9 +-- .../README_EN.md | 9 +-- .../Solution.rs | 9 +-- .../Solution.rs | 8 +-- .../0200-0299/0252.Meeting Rooms/Solution.rs | 2 +- .../0253.Meeting Rooms II/Solution.rs | 4 +- .../0200-0299/0258.Add Digits/Solution.rs | 5 +- solution/0200-0299/0274.H-Index/Solution.rs | 2 +- .../Solution.rs | 5 +- .../README.md | 7 +-- .../README_EN.md | 7 +-- .../Solution.rs | 7 +-- .../0296.Best Meeting Point/Solution.rs | 4 +- .../README.md | 6 +- .../README_EN.md | 6 +- .../Solution.rs | 6 +- .../Solution.rs | 14 ++--- .../README.md | 7 +-- .../README_EN.md | 7 +-- .../Solution.rs | 12 +--- .../0362.Design Hit Counter/README.md | 7 +-- .../0362.Design Hit Counter/README_EN.md | 7 +-- .../0362.Design Hit Counter/Solution.rs | 7 +-- .../README.md | 8 +-- .../README_EN.md | 8 +-- .../Solution.rs | 10 +--- .../0300-0399/0384.Shuffle an Array/README.md | 7 +-- .../0384.Shuffle an Array/README_EN.md | 7 +-- .../0384.Shuffle an Array/Solution.rs | 7 +-- .../0389.Find the Difference/Solution.rs | 10 +--- .../0396.Rotate Function/Solution.rs | 6 +- .../0399.Evaluate Division/Solution.rs | 13 +++-- solution/0400-0499/0403.Frog Jump/Solution.rs | 9 ++- .../0404.Sum of Left Leaves/Solution.rs | 2 +- .../0433.Minimum Genetic Mutation/Solution.rs | 2 +- .../0445.Add Two Numbers II/Solution.rs | 2 +- .../0445.Add Two Numbers II/Solution2.rs | 12 ++-- .../0450.Delete Node in a BST/Solution.rs | 4 +- solution/0400-0499/0454.4Sum II/Solution.rs | 2 +- solution/0400-0499/0460.LFU Cache/README.md | 7 +-- .../0400-0499/0460.LFU Cache/README_EN.md | 7 +-- solution/0400-0499/0460.LFU Cache/Solution.rs | 7 +-- .../0400-0499/0481.Magical String/Solution.rs | 6 +- .../0486.Predict the Winner/Solution.rs | 2 +- .../Solution.rs | 4 +- .../Solution.rs | 2 +- .../Solution2.rs | 2 +- .../Solution.rs | 2 +- .../Solution2.rs | 2 +- .../0528.Random Pick with Weight/README.md | 6 +- .../0528.Random Pick with Weight/README_EN.md | 6 +- .../0528.Random Pick with Weight/Solution.rs | 8 +-- .../Solution.rs | 2 +- solution/0500-0599/0542.01 Matrix/Solution.rs | 5 +- .../0543.Diameter of Binary Tree/Solution.rs | 2 +- .../0572.Subtree of Another Tree/Solution.rs | 18 +++--- .../0500-0599/0591.Tag Validator/Solution.rs | 7 +-- .../Solution.rs | 23 ++++---- .../0617.Merge Two Binary Trees/Solution.rs | 4 +- .../0622.Design Circular Queue/README.md | 11 +--- .../0622.Design Circular Queue/README_EN.md | 11 +--- .../0622.Design Circular Queue/Solution.rs | 11 +--- .../Solution.rs | 2 +- .../0600-0699/0645.Set Mismatch/Solution.rs | 7 ++- .../0652.Find Duplicate Subtrees/Solution.rs | 6 +- .../Solution.rs | 4 +- .../0654.Maximum Binary Tree/Solution.rs | 16 ++---- .../0655.Print Binary Tree/Solution.rs | 20 +++++-- .../Solution.rs | 4 +- .../Solution.rs | 20 +++---- .../0676.Implement Magic Dictionary/README.md | 7 +-- .../README_EN.md | 7 +-- .../Solution.rs | 14 +---- .../0687.Longest Univalue Path/Solution.rs | 8 ++- .../0691.Stickers to Spell Word/Solution.rs | 2 +- .../0707.Design Linked List/README.md | 10 +--- .../0707.Design Linked List/README_EN.md | 10 +--- .../0707.Design Linked List/Solution.rs | 30 +++------- .../Solution.rs | 18 +++--- .../0728.Self Dividing Numbers/Solution.rs | 20 +++---- .../0700-0799/0729.My Calendar I/README.md | 6 +- .../0700-0799/0729.My Calendar I/README_EN.md | 6 +- .../0700-0799/0729.My Calendar I/Solution.rs | 6 +- .../0767.Reorganize String/Solution.rs | 2 +- .../0778.Swim in Rising Water/Solution.rs | 12 +--- .../0785.Is Graph Bipartite/Solution.rs | 2 +- .../0791.Custom Sort String/Solution.rs | 4 +- .../0804.Unique Morse Code Words/Solution.rs | 29 +--------- .../0814.Binary Tree Pruning/Solution.rs | 2 +- .../0819.Most Common Word/Solution.rs | 5 +- .../0827.Making A Large Island/Solution.rs | 15 +++-- .../0872.Leaf-Similar Trees/Solution.rs | 8 +-- .../Solution.rs | 21 +------ .../Solution.rs | 18 +++--- .../0901.Online Stock Span/README.md | 6 +- .../0901.Online Stock Span/README_EN.md | 6 +- .../0901.Online Stock Span/Solution.rs | 6 +- .../0907.Sum of Subarray Minimums/Solution.rs | 5 +- .../0933.Number of Recent Calls/README.md | 6 +- .../0933.Number of Recent Calls/README_EN.md | 6 +- .../0933.Number of Recent Calls/Solution.rs | 6 +- .../0936.Stamping The Sequence/Solution.rs | 7 +-- .../Solution.rs | 10 ++-- .../0940.Distinct Subsequences II/Solution.rs | 15 +++-- .../0942.DI String Match/Solution.rs | 16 +++--- .../Solution.rs | 10 +--- .../0965.Univalued Binary Tree/Solution.rs | 2 +- .../Solution.rs | 5 +- .../Solution.rs | 2 +- .../0994.Rotting Oranges/Solution.rs | 11 ++-- .../0998.Maximum Binary Tree II/Solution.rs | 18 +++--- .../Solution.rs | 18 +++--- .../Solution.rs | 2 +- .../1036.Escape a Large Maze/Solution.rs | 15 +++-- .../Solution.rs | 2 +- .../1048.Longest String Chain/Solution.rs | 2 +- .../1049.Last Stone Weight II/Solution.rs | 2 +- .../1000-1099/1094.Car Pooling/Solution.rs | 6 +- .../Solution.rs | 11 ++-- .../Solution.rs | 12 +--- .../1197.Minimum Knight Moves/Solution.rs | 2 +- .../1197.Minimum Knight Moves/Solution2.rs | 18 ++---- .../Solution.rs | 2 +- .../1229.Meeting Scheduler/Solution.rs | 6 +- .../1244.Design A Leaderboard/Solution.rs | 10 ++-- .../Solution.rs | 2 +- .../1302.Deepest Leaves Sum/Solution.rs | 2 +- .../Solution.rs | 2 +- .../Solution.rs | 6 +- .../Solution.rs | 8 +-- .../Solution.rs | 4 +- .../Solution.rs | 5 +- .../1436.Destination City/Solution.rs | 5 +- .../Solution.rs | 7 +-- .../Solution.rs | 2 +- .../Solution.rs | 14 +++-- .../Solution.rs | 2 +- .../1603.Design Parking System/README.md | 6 +- .../1603.Design Parking System/README_EN.md | 6 +- .../1603.Design Parking System/Solution.rs | 6 +- .../Solution.rs | 2 +- .../1656.Design an Ordered Stream/README.md | 6 +- .../README_EN.md | 6 +- .../1656.Design an Ordered Stream/Solution.rs | 11 ++-- .../Solution.rs | 6 +- .../1672.Richest Customer Wealth/Solution.rs | 6 +- .../Solution2.rs | 6 +- .../1694.Reformat Phone Number/Solution.rs | 5 +- .../Solution.rs | 4 +- .../Solution.rs | 14 ++--- .../Solution.rs | 5 +- .../Solution.rs | 13 +++-- .../README.md | 8 +-- .../README_EN.md | 8 +-- .../Solution.rs | 8 +-- .../1862.Sum of Floored Pairs/Solution.rs | 9 ++- .../Solution.rs | 5 +- .../Solution.rs | 4 +- .../Solution2.rs | 2 +- .../Solution.rs | 2 +- .../2032.Two Out of Three/Solution.rs | 13 ++--- .../2043.Simple Bank System/README.md | 8 +-- .../2043.Simple Bank System/README_EN.md | 8 +-- .../2043.Simple Bank System/Solution.rs | 8 +-- .../2100-2199/2103.Rings and Rods/Solution.rs | 5 +- .../Solution.rs | 5 +- .../2132.Stamping the Grid/Solution.rs | 5 +- .../Solution.rs | 5 +- .../Solution.rs | 5 +- .../Solution.rs | 5 +- .../Solution.rs | 2 +- .../Solution.rs | 14 ++--- .../Solution.rs | 2 +- .../Solution.rs | 7 +-- .../Solution.rs | 2 +- .../Solution.rs | 8 +-- .../2200-2299/2293.Min Max Game/Solution.rs | 2 +- .../Solution.rs | 2 +- .../README.md | 7 +-- .../README_EN.md | 7 +-- .../Solution.rs | 7 +-- .../Solution.rs | 2 +- .../Solution.rs | 18 +++--- .../2418.Sort the People/Solution.rs | 5 +- .../Solution.rs | 20 +++---- .../Solution.rs | 2 +- .../2451.Odd String Difference/Solution2.rs | 9 +-- .../Solution.rs | 10 +--- .../Solution2.rs | 6 +- .../Solution.rs | 2 +- .../Solution2.rs | 13 +---- .../2512.Reward Top K Students/Solution.rs | 9 +-- .../Solution.rs | 4 +- .../Solution2.rs | 3 +- .../Solution2.rs | 9 ++- .../Solution2.rs | 7 +-- .../Solution.rs | 7 +-- .../Solution.rs | 4 +- .../Solution.rs | 5 +- .../Solution.rs | 4 +- .../Solution.rs | 5 +- .../2590.Design a Todo List/Solution.rs | 42 +++++--------- .../Solution.rs | 2 +- .../2643.Row With Maximum Ones/Solution.rs | 5 +- .../2600-2699/2652.Sum Multiples/Solution2.rs | 4 +- .../Solution.rs" | 2 +- .../2671.Frequency Tracker/README.md | 8 +-- .../2671.Frequency Tracker/README_EN.md | 8 +-- .../2671.Frequency Tracker/Solution.rs | 8 +-- .../2679.Sum in a Matrix/Solution.rs | 8 +-- .../2742.Painting the Walls/Solution.rs | 8 +-- .../Solution.rs | 5 +- .../Solution.rs | 10 ++-- .../Solution.rs | 3 +- .../Solution.rs | 5 +- .../Solution.rs | 2 +- .../Solution.rs | 9 +-- .../Solution.rs | 5 +- .../Solution2.rs | 5 +- .../2974.Minimum Number Game/Solution.rs | 2 +- 358 files changed, 875 insertions(+), 1757 deletions(-) diff --git a/.github/workflows/prettier.yml b/.github/workflows/prettier.yml index 3487fa7874225..3cc69b529c371 100644 --- a/.github/workflows/prettier.yml +++ b/.github/workflows/prettier.yml @@ -29,7 +29,7 @@ jobs: - name: Run prettier run: | git config --global core.quotepath off - changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" | grep -E '\.js$|\.ts$|\.php$|\.sql$|\.rs$|\.md$' || true) + changed_files=$(git diff --name-only "${{ github.event.pull_request.base.sha }}" | grep -E '\.js$|\.ts$|\.php$|\.sql$|\.md$' || true) if [ -n "$changed_files" ]; then echo "Running prettier on the changed files" echo "$changed_files" | xargs -d '\n' npx prettier --write diff --git a/.prettierrc b/.prettierrc index 526ad72f0b02a..d5e29fa69e318 100644 --- a/.prettierrc +++ b/.prettierrc @@ -17,5 +17,5 @@ "options": { "parser": "mysql" } } ], - "plugins": ["prettier-plugin-rust", "prettier-plugin-sql-cst", "@prettier/plugin-php"] + "plugins": ["prettier-plugin-sql-cst", "@prettier/plugin-php"] } diff --git a/basic/sorting/HeapSort/README.md b/basic/sorting/HeapSort/README.md index cff9934b0abb2..a4506916e9ae2 100644 --- a/basic/sorting/HeapSort/README.md +++ b/basic/sorting/HeapSort/README.md @@ -207,19 +207,13 @@ fn sink(nums: &mut Vec, mut i: usize, n: usize) { fn main() -> io::Result<()> { let mut s = String::new(); io::stdin().read_line(&mut s)?; - let s: Vec = s - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let s: Vec = s.split(' ').map(|s| s.trim().parse().unwrap()).collect(); // let n = s[0]; let m = s[1]; let mut nums = String::new(); io::stdin().read_line(&mut nums)?; - let mut nums: Vec = nums - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let mut nums: Vec = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect(); heap_sort(&mut nums); for num in nums.iter().take(m) { diff --git a/basic/sorting/HeapSort/Solution.rs b/basic/sorting/HeapSort/Solution.rs index ed0654aaff1b2..bbd667121330d 100644 --- a/basic/sorting/HeapSort/Solution.rs +++ b/basic/sorting/HeapSort/Solution.rs @@ -37,19 +37,13 @@ fn sink(nums: &mut Vec, mut i: usize, n: usize) { fn main() -> io::Result<()> { let mut s = String::new(); io::stdin().read_line(&mut s)?; - let s: Vec = s - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let s: Vec = s.split(' ').map(|s| s.trim().parse().unwrap()).collect(); // let n = s[0]; let m = s[1]; let mut nums = String::new(); io::stdin().read_line(&mut nums)?; - let mut nums: Vec = nums - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let mut nums: Vec = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect(); heap_sort(&mut nums); for num in nums.iter().take(m) { diff --git a/basic/sorting/MergeSort/Main.rs b/basic/sorting/MergeSort/Main.rs index 9165da9ec0dd9..a9fcb04189690 100644 --- a/basic/sorting/MergeSort/Main.rs +++ b/basic/sorting/MergeSort/Main.rs @@ -43,10 +43,7 @@ fn main() -> io::Result<()> { let mut nums = String::new(); io::stdin().read_line(&mut nums)?; - let mut nums: Vec = nums - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let mut nums: Vec = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect(); merge_sort(&mut nums, 0, n - 1); for num in nums.iter() { diff --git a/basic/sorting/MergeSort/Solution.rs b/basic/sorting/MergeSort/Solution.rs index 9165da9ec0dd9..a9fcb04189690 100644 --- a/basic/sorting/MergeSort/Solution.rs +++ b/basic/sorting/MergeSort/Solution.rs @@ -43,10 +43,7 @@ fn main() -> io::Result<()> { let mut nums = String::new(); io::stdin().read_line(&mut nums)?; - let mut nums: Vec = nums - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let mut nums: Vec = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect(); merge_sort(&mut nums, 0, n - 1); for num in nums.iter() { diff --git a/basic/sorting/QuickSort/Main.rs b/basic/sorting/QuickSort/Main.rs index 766e3579ae083..ea152734e1e42 100644 --- a/basic/sorting/QuickSort/Main.rs +++ b/basic/sorting/QuickSort/Main.rs @@ -37,10 +37,7 @@ fn main() -> io::Result<()> { let mut nums = String::new(); io::stdin().read_line(&mut nums)?; - let mut nums: Vec = nums - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let mut nums: Vec = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect(); quick_sort(&mut nums, 0, n - 1); for num in nums.iter() { diff --git a/basic/sorting/QuickSort/README.md b/basic/sorting/QuickSort/README.md index e17d4acb80f5a..82b504c90803b 100644 --- a/basic/sorting/QuickSort/README.md +++ b/basic/sorting/QuickSort/README.md @@ -267,10 +267,7 @@ fn main() -> io::Result<()> { let mut nums = String::new(); io::stdin().read_line(&mut nums)?; - let mut nums: Vec = nums - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let mut nums: Vec = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect(); quick_sort(&mut nums, 0, n - 1); for num in nums.iter() { diff --git a/basic/sorting/QuickSort/Solution.rs b/basic/sorting/QuickSort/Solution.rs index 766e3579ae083..ea152734e1e42 100644 --- a/basic/sorting/QuickSort/Solution.rs +++ b/basic/sorting/QuickSort/Solution.rs @@ -37,10 +37,7 @@ fn main() -> io::Result<()> { let mut nums = String::new(); io::stdin().read_line(&mut nums)?; - let mut nums: Vec = nums - .split(' ') - .map(|s| s.trim().parse().unwrap()) - .collect(); + let mut nums: Vec = nums.split(' ').map(|s| s.trim().parse().unwrap()).collect(); quick_sort(&mut nums, 0, n - 1); for num in nums.iter() { diff --git a/lcci/01.03.String to URL/Solution2.rs b/lcci/01.03.String to URL/Solution2.rs index 2ef9f1bb8b9db..7cc2912f38034 100644 --- a/lcci/01.03.String to URL/Solution2.rs +++ b/lcci/01.03.String to URL/Solution2.rs @@ -3,7 +3,11 @@ impl Solution { s.chars() .take(length as usize) .map(|c| { - if c == ' ' { "%20".to_string() } else { c.to_string() } + if c == ' ' { + "%20".to_string() + } else { + c.to_string() + } }) .collect() } diff --git a/lcci/02.05.Sum Lists/Solution.rs b/lcci/02.05.Sum Lists/Solution.rs index 4ee4affa8b99f..f396419173da0 100644 --- a/lcci/02.05.Sum Lists/Solution.rs +++ b/lcci/02.05.Sum Lists/Solution.rs @@ -1,7 +1,7 @@ impl Solution { pub fn add_two_numbers( mut l1: Option>, - mut l2: Option> + mut l2: Option>, ) -> Option> { let mut dummy = Some(Box::new(ListNode::new(0))); let mut cur = dummy.as_mut(); diff --git a/lcci/03.02.Min Stack/README.md b/lcci/03.02.Min Stack/README.md index 45a8d74c4e478..fb22c3c2783a5 100644 --- a/lcci/03.02.Min Stack/README.md +++ b/lcci/03.02.Min Stack/README.md @@ -274,14 +274,7 @@ impl MinStack { fn get_min(&self) -> i32 { *self.min_stack.back().unwrap() } -}/** - * Your MinStack object will be instantiated and called as such: - * let obj = MinStack::new(); - * obj.push(x); - * obj.pop(); - * let ret_3: i32 = obj.top(); - * let ret_4: i32 = obj.get_min(); - */ +} ``` #### C# diff --git a/lcci/03.02.Min Stack/README_EN.md b/lcci/03.02.Min Stack/README_EN.md index 0b3e68c2cbfcb..666fe77dbdd34 100644 --- a/lcci/03.02.Min Stack/README_EN.md +++ b/lcci/03.02.Min Stack/README_EN.md @@ -294,14 +294,7 @@ impl MinStack { fn get_min(&self) -> i32 { *self.min_stack.back().unwrap() } -}/** - * Your MinStack object will be instantiated and called as such: - * let obj = MinStack::new(); - * obj.push(x); - * obj.pop(); - * let ret_3: i32 = obj.top(); - * let ret_4: i32 = obj.get_min(); - */ +} ``` #### C# diff --git a/lcci/03.02.Min Stack/Solution.rs b/lcci/03.02.Min Stack/Solution.rs index fcbc64f5abc63..713ca251733ca 100644 --- a/lcci/03.02.Min Stack/Solution.rs +++ b/lcci/03.02.Min Stack/Solution.rs @@ -11,7 +11,10 @@ struct MinStack { impl MinStack { /** initialize your data structure here. */ fn new() -> Self { - Self { stack: VecDeque::new(), min_stack: VecDeque::new() } + Self { + stack: VecDeque::new(), + min_stack: VecDeque::new(), + } } fn push(&mut self, x: i32) { @@ -35,11 +38,4 @@ impl MinStack { fn get_min(&self) -> i32 { *self.min_stack.back().unwrap() } -}/** - * Your MinStack object will be instantiated and called as such: - * let obj = MinStack::new(); - * obj.push(x); - * obj.pop(); - * let ret_3: i32 = obj.top(); - * let ret_4: i32 = obj.get_min(); - */ +} diff --git a/lcci/03.04.Implement Queue using Stacks/README.md b/lcci/03.04.Implement Queue using Stacks/README.md index d9334f3e5ad09..aa8fa989f56b8 100644 --- a/lcci/03.04.Implement Queue using Stacks/README.md +++ b/lcci/03.04.Implement Queue using Stacks/README.md @@ -314,14 +314,7 @@ impl MyQueue { } } } -}/** - * Your MyQueue object will be instantiated and called as such: - * let obj = MyQueue::new(); - * obj.push(x); - * let ret_2: i32 = obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.empty(); - */ +} ``` #### Swift diff --git a/lcci/03.04.Implement Queue using Stacks/README_EN.md b/lcci/03.04.Implement Queue using Stacks/README_EN.md index 3203a0cf45f70..71080d2024622 100644 --- a/lcci/03.04.Implement Queue using Stacks/README_EN.md +++ b/lcci/03.04.Implement Queue using Stacks/README_EN.md @@ -346,14 +346,7 @@ impl MyQueue { } } } -}/** - * Your MyQueue object will be instantiated and called as such: - * let obj = MyQueue::new(); - * obj.push(x); - * let ret_2: i32 = obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.empty(); - */ +} ``` #### Swift diff --git a/lcci/03.04.Implement Queue using Stacks/Solution.rs b/lcci/03.04.Implement Queue using Stacks/Solution.rs index a7c5fb57a4170..a08427c055f69 100644 --- a/lcci/03.04.Implement Queue using Stacks/Solution.rs +++ b/lcci/03.04.Implement Queue using Stacks/Solution.rs @@ -38,11 +38,4 @@ impl MyQueue { } } } -}/** - * Your MyQueue object will be instantiated and called as such: - * let obj = MyQueue::new(); - * obj.push(x); - * let ret_2: i32 = obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.empty(); - */ +} diff --git a/lcci/03.05.Sort of Stacks/README.md b/lcci/03.05.Sort of Stacks/README.md index c1a2ee7701534..f0c3853f11e40 100644 --- a/lcci/03.05.Sort of Stacks/README.md +++ b/lcci/03.05.Sort of Stacks/README.md @@ -329,14 +329,7 @@ impl SortedStack { fn is_empty(&self) -> bool { self.stk.is_empty() } -}/** - * Your SortedStack object will be instantiated and called as such: - * let obj = SortedStack::new(); - * obj.push(val); - * obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.is_empty(); - */ +} ``` #### Swift diff --git a/lcci/03.05.Sort of Stacks/README_EN.md b/lcci/03.05.Sort of Stacks/README_EN.md index e7070dcb7611c..23b496f732a01 100644 --- a/lcci/03.05.Sort of Stacks/README_EN.md +++ b/lcci/03.05.Sort of Stacks/README_EN.md @@ -343,14 +343,7 @@ impl SortedStack { fn is_empty(&self) -> bool { self.stk.is_empty() } -}/** - * Your SortedStack object will be instantiated and called as such: - * let obj = SortedStack::new(); - * obj.push(val); - * obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.is_empty(); - */ +} ``` #### Swift diff --git a/lcci/03.05.Sort of Stacks/Solution.rs b/lcci/03.05.Sort of Stacks/Solution.rs index 67e714c103769..917c648979c0e 100644 --- a/lcci/03.05.Sort of Stacks/Solution.rs +++ b/lcci/03.05.Sort of Stacks/Solution.rs @@ -34,17 +34,14 @@ impl SortedStack { } fn peek(&self) -> i32 { - if self.is_empty() { -1 } else { *self.stk.back().unwrap() } + if self.is_empty() { + -1 + } else { + *self.stk.back().unwrap() + } } fn is_empty(&self) -> bool { self.stk.is_empty() } -}/** - * Your SortedStack object will be instantiated and called as such: - * let obj = SortedStack::new(); - * obj.push(val); - * obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.is_empty(); - */ +} diff --git a/lcci/03.06.Animal Shelter/README.md b/lcci/03.06.Animal Shelter/README.md index 08d9549b6b479..81bfb00561687 100644 --- a/lcci/03.06.Animal Shelter/README.md +++ b/lcci/03.06.Animal Shelter/README.md @@ -331,14 +331,7 @@ impl AnimalShelf { vec![cat, 0] } } -}/** - * Your AnimalShelf object will be instantiated and called as such: - * let obj = AnimalShelf::new(); - * obj.enqueue(animal); - * let ret_2: Vec = obj.dequeue_any(); - * let ret_3: Vec = obj.dequeue_dog(); - * let ret_4: Vec = obj.dequeue_cat(); - */ +} ``` #### Swift diff --git a/lcci/03.06.Animal Shelter/README_EN.md b/lcci/03.06.Animal Shelter/README_EN.md index 1732b08d89c39..c0538b2910fdf 100644 --- a/lcci/03.06.Animal Shelter/README_EN.md +++ b/lcci/03.06.Animal Shelter/README_EN.md @@ -345,14 +345,7 @@ impl AnimalShelf { vec![cat, 0] } } -}/** - * Your AnimalShelf object will be instantiated and called as such: - * let obj = AnimalShelf::new(); - * obj.enqueue(animal); - * let ret_2: Vec = obj.dequeue_any(); - * let ret_3: Vec = obj.dequeue_dog(); - * let ret_4: Vec = obj.dequeue_cat(); - */ +} ``` #### Swift diff --git a/lcci/03.06.Animal Shelter/Solution.rs b/lcci/03.06.Animal Shelter/Solution.rs index 687d5376e3d4e..5e7490626d58f 100644 --- a/lcci/03.06.Animal Shelter/Solution.rs +++ b/lcci/03.06.Animal Shelter/Solution.rs @@ -16,9 +16,8 @@ impl AnimalShelf { } fn dequeue_any(&mut self) -> Vec { - if - self.q[0].is_empty() || - (!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap()) + if self.q[0].is_empty() + || (!self.q[1].is_empty() && self.q[1].front().unwrap() < self.q[0].front().unwrap()) { self.dequeue_dog() } else { @@ -43,11 +42,4 @@ impl AnimalShelf { vec![cat, 0] } } -}/** - * Your AnimalShelf object will be instantiated and called as such: - * let obj = AnimalShelf::new(); - * obj.enqueue(animal); - * let ret_2: Vec = obj.dequeue_any(); - * let ret_3: Vec = obj.dequeue_dog(); - * let ret_4: Vec = obj.dequeue_cat(); - */ +} diff --git a/lcci/04.02.Minimum Height Tree/Solution.rs b/lcci/04.02.Minimum Height Tree/Solution.rs index 75ff9ab26d445..38864c1e10cd1 100644 --- a/lcci/04.02.Minimum Height Tree/Solution.rs +++ b/lcci/04.02.Minimum Height Tree/Solution.rs @@ -16,23 +16,19 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(nums: &Vec, l: usize, r: usize) -> Option>> { if l >= r { return None; } let mid = (l + r) >> 1; - Some( - Rc::new( - RefCell::new(TreeNode { - val: nums[mid], - left: Self::dfs(nums, l, mid), - right: Self::dfs(nums, mid + 1, r), - }) - ) - ) + Some(Rc::new(RefCell::new(TreeNode { + val: nums[mid], + left: Self::dfs(nums, l, mid), + right: Self::dfs(nums, mid + 1, r), + }))) } pub fn sorted_array_to_bst(nums: Vec) -> Option>> { Self::dfs(&nums, 0, nums.len()) diff --git a/lcci/04.03.List of Depth/Solution.rs b/lcci/04.03.List of Depth/Solution.rs index 56e859cbc4ef5..f1442bdbbcc07 100644 --- a/lcci/04.03.List of Depth/Solution.rs +++ b/lcci/04.03.List of Depth/Solution.rs @@ -32,9 +32,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn list_of_depth(tree: Option>>) -> Vec>> { let mut res = vec![]; diff --git a/lcci/04.05.Legal Binary Search Tree/Solution.rs b/lcci/04.05.Legal Binary Search Tree/Solution.rs index e1cdfad146d8b..2de4f9512578e 100644 --- a/lcci/04.05.Legal Binary Search Tree/Solution.rs +++ b/lcci/04.05.Legal Binary Search Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, prev: &mut Option) -> bool { if root.is_none() { diff --git a/lcci/04.10.Check SubTree/Solution.rs b/lcci/04.10.Check SubTree/Solution.rs index 7218ff279bc8d..f67d338fb7e32 100644 --- a/lcci/04.10.Check SubTree/Solution.rs +++ b/lcci/04.10.Check SubTree/Solution.rs @@ -16,17 +16,17 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(t1: &Option>>, t2: &Option>>) -> bool { match (t1, t2) { (Some(node1), Some(node2)) => { let n1 = node1.borrow(); let n2 = node2.borrow(); - n1.val == n2.val && - Solution::dfs(&n1.left, &n2.left) && - Solution::dfs(&n1.right, &n2.right) + n1.val == n2.val + && Solution::dfs(&n1.left, &n2.left) + && Solution::dfs(&n1.right, &n2.right) } (None, Some(_)) => false, (Some(_), None) => false, @@ -36,15 +36,15 @@ impl Solution { pub fn check_sub_tree( t1: Option>>, - t2: Option>> + t2: Option>>, ) -> bool { match (t1, t2) { (Some(node1), Some(node2)) => { let n1 = node1.borrow(); let n2 = node2.borrow(); - Solution::dfs(&Some(Rc::clone(&node1)), &Some(Rc::clone(&node2))) || - Solution::check_sub_tree(n1.left.clone(), Some(Rc::clone(&node2))) || - Solution::check_sub_tree(n1.right.clone(), Some(Rc::clone(&node2))) + Solution::dfs(&Some(Rc::clone(&node1)), &Some(Rc::clone(&node2))) + || Solution::check_sub_tree(n1.left.clone(), Some(Rc::clone(&node2))) + || Solution::check_sub_tree(n1.right.clone(), Some(Rc::clone(&node2))) } (Some(_), None) => true, (None, Some(_)) => false, diff --git a/lcci/04.12.Paths with Sum/Solution.rs b/lcci/04.12.Paths with Sum/Solution.rs index 714389a72ba4b..4cfb51f0d44d5 100644 --- a/lcci/04.12.Paths with Sum/Solution.rs +++ b/lcci/04.12.Paths with Sum/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; impl Solution { pub fn path_sum(root: Option>>, sum: i32) -> i32 { let mut cnt = HashMap::new(); @@ -30,7 +30,7 @@ impl Solution { root: Option>>, sum: i32, s: i32, - cnt: &mut HashMap + cnt: &mut HashMap, ) -> i32 { if let Some(node) = root { let node = node.borrow(); diff --git a/lcci/08.02.Robot in a Grid/Solution.rs b/lcci/08.02.Robot in a Grid/Solution.rs index 6c6e7a5d7adad..3f121643bd9ce 100644 --- a/lcci/08.02.Robot in a Grid/Solution.rs +++ b/lcci/08.02.Robot in a Grid/Solution.rs @@ -5,10 +5,9 @@ impl Solution { } path.push(vec![i as i32, j as i32]); grid[i as usize][j as usize] = 1; - if - (i + 1 == grid.len() && j + 1 == grid[0].len()) || - Self::dfs(grid, path, i + 1, j) || - Self::dfs(grid, path, i, j + 1) + if (i + 1 == grid.len() && j + 1 == grid[0].len()) + || Self::dfs(grid, path, i + 1, j) + || Self::dfs(grid, path, i, j + 1) { return true; } diff --git a/lcci/10.02.Group Anagrams/Solution.rs b/lcci/10.02.Group Anagrams/Solution.rs index 85ae009c61d49..4773defd8a6c6 100644 --- a/lcci/10.02.Group Anagrams/Solution.rs +++ b/lcci/10.02.Group Anagrams/Solution.rs @@ -9,9 +9,7 @@ impl Solution { cs.sort(); cs.iter().collect::() }; - map.entry(key) - .or_insert(vec![]) - .push(s); + map.entry(key).or_insert(vec![]).push(s); } map.into_values().collect() } diff --git a/lcci/16.02.Words Frequency/README.md b/lcci/16.02.Words Frequency/README.md index 96046d7d1dd37..af8891fe3f4e9 100644 --- a/lcci/16.02.Words Frequency/README.md +++ b/lcci/16.02.Words Frequency/README.md @@ -194,11 +194,7 @@ impl WordsFrequency { fn get(&self, word: String) -> i32 { *self.cnt.get(&word).unwrap_or(&0) } -}/** - * Your WordsFrequency object will be instantiated and called as such: - * let obj = WordsFrequency::new(book); - * let ret_1: i32 = obj.get(word); - */ +} ``` #### JavaScript diff --git a/lcci/16.02.Words Frequency/README_EN.md b/lcci/16.02.Words Frequency/README_EN.md index 91b1267402184..8d3a09401c7a2 100644 --- a/lcci/16.02.Words Frequency/README_EN.md +++ b/lcci/16.02.Words Frequency/README_EN.md @@ -208,11 +208,7 @@ impl WordsFrequency { fn get(&self, word: String) -> i32 { *self.cnt.get(&word).unwrap_or(&0) } -}/** - * Your WordsFrequency object will be instantiated and called as such: - * let obj = WordsFrequency::new(book); - * let ret_1: i32 = obj.get(word); - */ +} ``` #### JavaScript diff --git a/lcci/16.02.Words Frequency/Solution.rs b/lcci/16.02.Words Frequency/Solution.rs index bbab4feff97a9..f136c6d6242f2 100644 --- a/lcci/16.02.Words Frequency/Solution.rs +++ b/lcci/16.02.Words Frequency/Solution.rs @@ -19,8 +19,4 @@ impl WordsFrequency { fn get(&self, word: String) -> i32 { *self.cnt.get(&word).unwrap_or(&0) } -}/** - * Your WordsFrequency object will be instantiated and called as such: - * let obj = WordsFrequency::new(book); - * let ret_1: i32 = obj.get(word); - */ +} diff --git a/lcci/16.25.LRU Cache/README.md b/lcci/16.25.LRU Cache/README.md index 68f73a60b87bf..2faece705d8ad 100644 --- a/lcci/16.25.LRU Cache/README.md +++ b/lcci/16.25.LRU Cache/README.md @@ -548,12 +548,7 @@ impl LRUCache { None => None, } } -}/** - * Your LRUCache object will be instantiated and called as such: - * let obj = LRUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} ``` #### C# diff --git a/lcci/16.25.LRU Cache/README_EN.md b/lcci/16.25.LRU Cache/README_EN.md index 11e480ea76183..615b6cc4fdf04 100644 --- a/lcci/16.25.LRU Cache/README_EN.md +++ b/lcci/16.25.LRU Cache/README_EN.md @@ -562,12 +562,7 @@ impl LRUCache { None => None, } } -}/** - * Your LRUCache object will be instantiated and called as such: - * let obj = LRUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} ``` #### C# diff --git a/lcci/16.25.LRU Cache/Solution.rs b/lcci/16.25.LRU Cache/Solution.rs index 76b8fecb7769d..c02f601eb4a60 100644 --- a/lcci/16.25.LRU Cache/Solution.rs +++ b/lcci/16.25.LRU Cache/Solution.rs @@ -120,9 +120,4 @@ impl LRUCache { None => None, } } -}/** - * Your LRUCache object will be instantiated and called as such: - * let obj = LRUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} diff --git "a/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.rs" index 3aba48162d9e2..d2f84a0f4a543 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23007. \351\207\215\345\273\272\344\272\214\345\217\211\346\240\221/Solution.rs" @@ -16,27 +16,20 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn help(preorder: &[i32], inorder: &[i32]) -> Option>> { if inorder.is_empty() { return None; } let val = preorder[0]; - let i = inorder - .iter() - .position(|num| *num == val) - .unwrap(); - Some( - Rc::new( - RefCell::new(TreeNode { - val, - left: Self::help(&preorder[1..i + 1], &inorder[..i]), - right: Self::help(&preorder[i + 1..], &inorder[i + 1..]), - }) - ) - ) + let i = inorder.iter().position(|num| *num == val).unwrap(); + Some(Rc::new(RefCell::new(TreeNode { + val, + left: Self::help(&preorder[1..i + 1], &inorder[..i]), + right: Self::help(&preorder[i + 1..], &inorder[i + 1..]), + }))) } pub fn build_tree(preorder: Vec, inorder: Vec) -> Option>> { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" index 696d6fbb87275..972c372fb334b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/README.md" @@ -259,12 +259,7 @@ impl CQueue { } } } -}/** - * Your CQueue object will be instantiated and called as such: - * let obj = CQueue::new(); - * obj.append_tail(value); - * let ret_2: i32 = obj.delete_head(); - */ +} ``` #### JavaScript diff --git "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.rs" index 034edd21bf558..bf7e427bda0dc 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23009. \347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227/Solution.rs" @@ -30,9 +30,4 @@ impl CQueue { } } } -}/** - * Your CQueue object will be instantiated and called as such: - * let obj = CQueue::new(); - * obj.append_tail(value); - * let ret_2: i32 = obj.delete_head(); - */ +} diff --git "a/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.rs" index 479ca64d8fc71..cd4007820c713 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23012. \347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204/Solution.rs" @@ -4,7 +4,7 @@ impl Solution { chars: &Vec, i: usize, j: usize, - mut k: usize + mut k: usize, ) -> bool { if board[i][j] != chars[k] { return false; @@ -15,11 +15,10 @@ impl Solution { } let temp = board[i][j]; board[i][j] = ' '; - if - (i != 0 && Self::dfs(board, chars, i - 1, j, k)) || - (j != 0 && Self::dfs(board, chars, i, j - 1, k)) || - (i != board.len() - 1 && Self::dfs(board, chars, i + 1, j, k)) || - (j != board[0].len() - 1 && Self::dfs(board, chars, i, j + 1, k)) + if (i != 0 && Self::dfs(board, chars, i - 1, j, k)) + || (j != 0 && Self::dfs(board, chars, i, j - 1, k)) + || (i != board.len() - 1 && Self::dfs(board, chars, i + 1, j, k)) + || (j != board[0].len() - 1 && Self::dfs(board, chars, i, j + 1, k)) { return true; } diff --git "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution.rs" index 94199fc748cb2..117af81917f80 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution.rs" @@ -17,7 +17,7 @@ impl Solution { pub fn merge_two_lists( mut l1: Option>, - mut l2: Option> + mut l2: Option>, ) -> Option> { match (l1.is_some(), l2.is_some()) { (false, false) => None, diff --git "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution2.rs" "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution2.rs" index 6b39d8c9626d7..31e1cf11be04f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution2.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23025. \345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250/Solution2.rs" @@ -17,7 +17,7 @@ impl Solution { pub fn merge_two_lists( l1: Option>, - l2: Option> + l2: Option>, ) -> Option> { match (l1, l2) { (Some(mut n1), Some(mut n2)) => { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.rs" index 6cadc90c4cf93..f9e04fb7ffb4a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23026. \346\240\221\347\232\204\345\255\220\347\273\223\346\236\204/Solution.rs" @@ -16,27 +16,27 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn is_sub_structure( a: Option>>, - b: Option>> + b: Option>>, ) -> bool { Self::is_sub_structure_help(&a, &b) } fn is_sub_structure_help( a: &Option>>, - b: &Option>> + b: &Option>>, ) -> bool { if a.is_none() || b.is_none() { return false; } - Self::dfs(a, b) || - Self::is_sub_structure_help(&a.as_ref().unwrap().borrow().left, b) || - Self::is_sub_structure_help(&a.as_ref().unwrap().borrow().right, b) + Self::dfs(a, b) + || Self::is_sub_structure_help(&a.as_ref().unwrap().borrow().left, b) + || Self::is_sub_structure_help(&a.as_ref().unwrap().borrow().right, b) } fn dfs(a: &Option>>, b: &Option>>) -> bool { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/Solution.rs" index 01e8b1f4847eb..85a1ad927fa2f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23027. \344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217/Solution.rs" @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &mut Option>>) { if let Some(node) = root { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/Solution.rs" index a36212fa60696..384c7491c8efd 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23029. \351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265/Solution.rs" @@ -4,12 +4,8 @@ impl Solution { if matrix.len() == 0 { return ans; } - let (mut left, mut right, mut top, mut bottom) = ( - 0, - matrix[0].len() - 1, - 0, - matrix.len() - 1, - ); + let (mut left, mut right, mut top, mut bottom) = + (0, matrix[0].len() - 1, 0, matrix.len() - 1); loop { for i in left..right + 1 { ans.push(matrix[top][i]); diff --git "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" index 632509df1b53e..b79b7a64b0bbf 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/README.md" @@ -293,14 +293,7 @@ impl MinStack { fn get_min(&self) -> i32 { *self.min_stack.back().unwrap() } -}/** - * Your MinStack object will be instantiated and called as such: - * let obj = MinStack::new(); - * obj.push(x); - * obj.pop(); - * let ret_3: i32 = obj.top(); - * let ret_4: i32 = obj.get_min(); - */ +} ``` #### JavaScript diff --git "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/Solution.rs" index fcbc64f5abc63..713ca251733ca 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23030. \345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210/Solution.rs" @@ -11,7 +11,10 @@ struct MinStack { impl MinStack { /** initialize your data structure here. */ fn new() -> Self { - Self { stack: VecDeque::new(), min_stack: VecDeque::new() } + Self { + stack: VecDeque::new(), + min_stack: VecDeque::new(), + } } fn push(&mut self, x: i32) { @@ -35,11 +38,4 @@ impl MinStack { fn get_min(&self) -> i32 { *self.min_stack.back().unwrap() } -}/** - * Your MinStack object will be instantiated and called as such: - * let obj = MinStack::new(); - * obj.push(x); - * obj.pop(); - * let ret_3: i32 = obj.top(); - * let ret_4: i32 = obj.get_min(); - */ +} diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/Solution.rs" index 8295ae92fabe3..2ce0bc53a844d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - I. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221/Solution.rs" @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn level_order(root: Option>>) -> Vec { let mut ans = Vec::new(); diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/Solution.rs" index 208bec3aec18d..8c484c35ef16d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - II. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 II/Solution.rs" @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn level_order(root: Option>>) -> Vec> { let mut res = Vec::new(); diff --git "a/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/Solution.rs" index 6d1432b0e5535..96d522e713019 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23032 - III. \344\273\216\344\270\212\345\210\260\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221 III/Solution.rs" @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn level_order(root: Option>>) -> Vec> { let mut res = Vec::new(); diff --git "a/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/Solution.rs" index a5f33356ced69..84b2fb709c8a1 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23033. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227/Solution.rs" @@ -10,10 +10,8 @@ impl Solution { return false; } if val < root_val { - return ( - Self::dfs(start, i, root_val, postorder) && - Self::dfs(i + 1, end - 1, max_val, postorder) - ); + return (Self::dfs(start, i, root_val, postorder) + && Self::dfs(i + 1, end - 1, max_val, postorder)); } } Self::dfs(start, end - 1, max_val, postorder) diff --git "a/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/Solution.rs" index 04d5874645fe6..28aabcf121ce3 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23034. \344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204/Solution.rs" @@ -16,14 +16,14 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs( root: &Option>>, mut target: i32, t: &mut Vec, - ans: &mut Vec> + ans: &mut Vec>, ) { if let Some(node) = root.as_ref() { let node = node.borrow(); diff --git "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" index 53d8d1703d7d0..3bedc52233d3a 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/README.md" @@ -306,12 +306,7 @@ impl MedianFinder { } f64::from(self.nums[n >> 1] + self.nums[(n >> 1) - 1]) / 2.0 } -}/** - * Your MedianFinder object will be instantiated and called as such: - * let obj = MedianFinder::new(); - * obj.add_num(num); - * let ret_2: f64 = obj.find_median(); - */ +} ``` #### JavaScript diff --git "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.rs" index be3a7ac65744b..52b8117baf98c 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23041. \346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260/Solution.rs" @@ -33,9 +33,4 @@ impl MedianFinder { } f64::from(self.nums[n >> 1] + self.nums[(n >> 1) - 1]) / 2.0 } -}/** - * Your MedianFinder object will be instantiated and called as such: - * let obj = MedianFinder::new(); - * obj.add_num(num); - * let ret_2: f64 = obj.find_median(); - */ +} diff --git "a/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.rs" index a9fd968eaaeb4..3417604e55c3e 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23045. \346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260/Solution.rs" @@ -1,8 +1,6 @@ impl Solution { pub fn min_number(mut nums: Vec) -> String { nums.sort_by(|a, b| format!("{}{}", a, b).cmp(&format!("{}{}", b, a))); - nums.iter() - .map(|num| num.to_string()) - .collect() + nums.iter().map(|num| num.to_string()).collect() } } diff --git "a/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/Solution.rs" index 5e1c64d05ffa4..86410b82de5c4 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23054. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\345\244\247\350\212\202\347\202\271/Solution.rs" @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, arr: &mut Vec) { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/Solution.rs" index 8384b6c436c76..2b8ba49298662 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23055 - I. \344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246/Solution.rs" @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn max_depth(root: Option>>) -> i32 { match root { diff --git "a/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.rs" index fe28d0c91e750..840bb8d5bb640 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23055 - II. \345\271\263\350\241\241\344\272\214\345\217\211\346\240\221/Solution.rs" @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>) -> i32 { match root { @@ -34,9 +34,9 @@ impl Solution { Some(node) => { let mut node = node.borrow_mut(); let a = 10; - (Self::dfs(&node.left) - Self::dfs(&node.right)).abs() <= 1 && - Self::is_balanced(node.left.take()) && - Self::is_balanced(node.right.take()) + (Self::dfs(&node.left) - Self::dfs(&node.right)).abs() <= 1 + && Self::is_balanced(node.left.take()) + && Self::is_balanced(node.right.take()) } } } diff --git "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" index da9e316a220bb..f15c847e804c5 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" +++ "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/README.md" @@ -315,13 +315,7 @@ impl MaxQueue { } res } -}/** - * Your MaxQueue object will be instantiated and called as such: - * let obj = MaxQueue::new(); - * let ret_1: i32 = obj.max_value(); - * obj.push_back(value); - * let ret_3: i32 = obj.pop_front(); - */ +} ``` #### JavaScript diff --git "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/Solution.rs" index a01e139c882b5..02a7d1cd81d3f 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23059 - II. \351\230\237\345\210\227\347\232\204\346\234\200\345\244\247\345\200\274/Solution.rs" @@ -38,10 +38,4 @@ impl MaxQueue { } res } -}/** - * Your MaxQueue object will be instantiated and called as such: - * let obj = MaxQueue::new(); - * let ret_1: i32 = obj.max_value(); - * obj.push_back(value); - * let ret_3: i32 = obj.pop_front(); - */ +} diff --git "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.rs" index c98351dd8f0ce..405fe4715bb2d 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23064. \346\261\2021+2+\342\200\246+n/Solution.rs" @@ -1,12 +1,13 @@ impl Solution { pub fn sum_nums(mut n: i32) -> i32 { - n != 0 && - ( + n != 0 + && ( { n += Solution::sum_nums(n - 1); }, true, - ).1; + ) + .1; n } } diff --git "a/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.rs" index 317dcb8198277..03cc5e5cd802b 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23068 - I. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.rs" @@ -16,14 +16,14 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::cmp::Ordering; +use std::rc::Rc; impl Solution { pub fn lowest_common_ancestor( mut root: Option>>, p: Option>>, - q: Option>> + q: Option>>, ) -> Option>> { let p = p.unwrap().borrow().val; let q = q.unwrap().borrow().val; diff --git "a/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.rs" "b/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.rs" index e0673044d8cfe..e0c6cf5bdb3c5 100644 --- "a/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.rs" +++ "b/lcof/\351\235\242\350\257\225\351\242\23068 - II. \344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\350\277\221\345\205\254\345\205\261\347\245\226\345\205\210/Solution.rs" @@ -16,13 +16,13 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn lowest_common_ancestor( root: Option>>, p: Option>>, - q: Option>> + q: Option>>, ) -> Option>> { if root.is_none() || root == p || root == q { return root; @@ -30,12 +30,12 @@ impl Solution { let left = Self::lowest_common_ancestor( root.as_ref().unwrap().borrow_mut().left.take(), p.clone(), - q.clone() + q.clone(), ); let right = Self::lowest_common_ancestor( root.as_ref().unwrap().borrow_mut().right.take(), p.clone(), - q.clone() + q.clone(), ); match (left.is_none(), right.is_none()) { (true, false) => right, diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/README.md" index 917f479ee71ee..47e1c107db878 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/README.md" @@ -578,12 +578,7 @@ impl LRUCache { None => None, } } -}/** - * Your LRUCache object will be instantiated and called as such: - * let obj = LRUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} ``` #### C# diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/Solution.rs" "b/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/Solution.rs" index 76b8fecb7769d..c02f601eb4a60 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/Solution.rs" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 031. \346\234\200\350\277\221\346\234\200\345\260\221\344\275\277\347\224\250\347\274\223\345\255\230/Solution.rs" @@ -120,9 +120,4 @@ impl LRUCache { None => None, } } -}/** - * Your LRUCache object will be instantiated and called as such: - * let obj = LRUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 038. \346\257\217\346\227\245\346\270\251\345\272\246/Solution.rs" "b/lcof2/\345\211\221\346\214\207 Offer II 038. \346\257\217\346\227\245\346\270\251\345\272\246/Solution.rs" index e0ab31eea7d5b..34f4dac3d96fe 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 038. \346\257\217\346\227\245\346\270\251\345\272\246/Solution.rs" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 038. \346\257\217\346\227\245\346\270\251\345\272\246/Solution.rs" @@ -7,7 +7,11 @@ impl Solution { while !stack.is_empty() && temperatures[*stack.last().unwrap()] <= temperatures[i] { stack.pop(); } - res[i] = if stack.is_empty() { 0 } else { (stack.last().unwrap() - i) as i32 }; + res[i] = if stack.is_empty() { + 0 + } else { + (stack.last().unwrap() - i) as i32 + }; stack.push(i); } res diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 051. \350\212\202\347\202\271\344\271\213\345\222\214\346\234\200\345\244\247\347\232\204\350\267\257\345\276\204/Solution.rs" "b/lcof2/\345\211\221\346\214\207 Offer II 051. \350\212\202\347\202\271\344\271\213\345\222\214\346\234\200\345\244\247\347\232\204\350\267\257\345\276\204/Solution.rs" index 5b24aa51d2e32..56f870e933db6 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 051. \350\212\202\347\202\271\344\271\213\345\222\214\346\234\200\345\244\247\347\232\204\350\267\257\345\276\204/Solution.rs" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 051. \350\212\202\347\202\271\344\271\213\345\222\214\346\234\200\345\244\247\347\232\204\350\267\257\345\276\204/Solution.rs" @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, res: &mut i32) -> i32 { if root.is_none() { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 052. \345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/Solution.rs" "b/lcof2/\345\211\221\346\214\207 Offer II 052. \345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/Solution.rs" index a8cdfc977c7a6..aad1eabcb8540 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 052. \345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/Solution.rs" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 052. \345\261\225\345\271\263\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221/Solution.rs" @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, vals: &mut Vec) { if root.is_none() { @@ -35,15 +35,11 @@ impl Solution { let mut dummy = Rc::new(RefCell::new(TreeNode::new(0))); for &val in vals.iter().rev() { let mut dummy = dummy.as_ref().borrow_mut(); - dummy.right = Some( - Rc::new( - RefCell::new(TreeNode { - val, - left: None, - right: dummy.right.take(), - }) - ) - ); + dummy.right = Some(Rc::new(RefCell::new(TreeNode { + val, + left: None, + right: dummy.right.take(), + }))); } let ans = dummy.as_ref().borrow_mut().right.take(); ans diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 054. \346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/Solution.rs" "b/lcof2/\345\211\221\346\214\207 Offer II 054. \346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/Solution.rs" index 2b4011a148916..b82cd9814ef1f 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 054. \346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/Solution.rs" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 054. \346\211\200\346\234\211\345\244\247\344\272\216\347\255\211\344\272\216\350\212\202\347\202\271\347\232\204\345\200\274\344\271\213\345\222\214/Solution.rs" @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, sum: &mut i32) { if let Some(node) = root { diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/README.md" "b/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/README.md" index 0097479160b7e..9047583f1c5ee 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/README.md" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/README.md" @@ -375,12 +375,7 @@ impl BSTIterator { fn has_next(&self) -> bool { !self.stack.is_empty() } -}/** - * Your BSTIterator object will be instantiated and called as such: - * let obj = BSTIterator::new(root); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} ``` #### JavaScript diff --git "a/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/Solution.rs" "b/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/Solution.rs" index 9380f07ddd8f2..de5749bc599d1 100644 --- "a/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/Solution.rs" +++ "b/lcof2/\345\211\221\346\214\207 Offer II 055. \344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\350\277\255\344\273\243\345\231\250/Solution.rs" @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; struct BSTIterator { stack: Vec, } @@ -41,9 +41,7 @@ impl BSTIterator { fn new(root: Option>>) -> Self { let mut stack = Vec::new(); Self::dfs(&root, &mut stack); - Self { - stack, - } + Self { stack } } fn next(&mut self) -> i32 { @@ -53,9 +51,4 @@ impl BSTIterator { fn has_next(&self) -> bool { !self.stack.is_empty() } -}/** - * Your BSTIterator object will be instantiated and called as such: - * let obj = BSTIterator::new(root); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} diff --git "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.rs" "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.rs" index a2a576e71ac40..3fbd5147995db 100644 --- "a/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.rs" +++ "b/lcp/LCP 06. \346\213\277\347\241\254\345\270\201/Solution.rs" @@ -1,8 +1,5 @@ impl Solution { pub fn min_count(coins: Vec) -> i32 { - coins - .iter() - .map(|&x| (x + 1) >> 1) - .sum::() + coins.iter().map(|&x| (x + 1) >> 1).sum::() } } diff --git a/package-lock.json b/package-lock.json index 488cbb7399892..93e256af88f15 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,6 @@ "husky": "^9.0.1", "lint-staged": "^15.2.7", "prettier": "^3.3.2", - "prettier-plugin-rust": "^0.1.9", "prettier-plugin-sql-cst": "^0.11.5" } }, @@ -343,9 +342,9 @@ } }, "node_modules/@types/node": { - "version": "20.14.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.6.tgz", - "integrity": "sha512-JbA0XIJPL1IiNnU7PFxDXyfAwcwVVrOoqyzzyQTyMeVhBzkJVMSkC1LlVsRQ2lpqiY4n6Bb9oCS6lzDKVQxbZw==", + "version": "20.14.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.7.tgz", + "integrity": "sha512-uTr2m2IbJJucF3KUxgnGOZvYbN0QgkGyWxG6973HCpMYFy2KfcgYuIwkJQMQkt1VbBMlvWRbpshFTLxnxCZjKQ==", "dev": true, "dependencies": { "undici-types": "~5.26.4" @@ -1137,12 +1136,15 @@ "dev": true }, "node_modules/is-core-module": { - "version": "2.13.1", - "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.13.1.tgz", - "integrity": "sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==", + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.14.0.tgz", + "integrity": "sha512-a5dFJih5ZLYlRtDc0dZWP7RiKr6xIKzmn/oAYCDvdLThadVgyJwlaoQPmRtMSpz+rk0OGAgIu+TcM9HUF0fk1A==", "dev": true, "dependencies": { - "hasown": "^2.0.0" + "hasown": "^2.0.2" + }, + "engines": { + "node": ">= 0.4" }, "funding": { "url": "https://github.com/sponsors/ljharb" @@ -1208,12 +1210,6 @@ "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", "dev": true }, - "node_modules/jinx-rust": { - "version": "0.1.6", - "resolved": "https://registry.npmjs.org/jinx-rust/-/jinx-rust-0.1.6.tgz", - "integrity": "sha512-qP+wtQL1PrDDFwtPKhNGtjWOmijCrKdfUHWTV2G/ikxfjrh+cjdvkQTmny9RAsVF0jiui9m+F0INWu4cuRcZeQ==", - "dev": true - }, "node_modules/jiti": { "version": "1.21.6", "resolved": "https://registry.npmjs.org/jiti/-/jiti-1.21.6.tgz", @@ -1730,31 +1726,6 @@ "url": "https://github.com/prettier/prettier?sponsor=1" } }, - "node_modules/prettier-plugin-rust": { - "version": "0.1.9", - "resolved": "https://registry.npmjs.org/prettier-plugin-rust/-/prettier-plugin-rust-0.1.9.tgz", - "integrity": "sha512-n1DTTJQaHMdnoG/+nKUvBm3EKsMVWsYES2UPCiOPiZdBrmuAO/pX++m7L3+Hz3uuhtddpH0HRKHB2F3jbtJBOQ==", - "dev": true, - "dependencies": { - "jinx-rust": "0.1.6", - "prettier": "^2.7.1" - } - }, - "node_modules/prettier-plugin-rust/node_modules/prettier": { - "version": "2.8.8", - "resolved": "https://registry.npmjs.org/prettier/-/prettier-2.8.8.tgz", - "integrity": "sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==", - "dev": true, - "bin": { - "prettier": "bin-prettier.js" - }, - "engines": { - "node": ">=10.13.0" - }, - "funding": { - "url": "https://github.com/prettier/prettier?sponsor=1" - } - }, "node_modules/prettier-plugin-sql-cst": { "version": "0.11.5", "resolved": "https://registry.npmjs.org/prettier-plugin-sql-cst/-/prettier-plugin-sql-cst-0.11.5.tgz", @@ -2054,9 +2025,9 @@ } }, "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "version": "5.5.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.2.tgz", + "integrity": "sha512-NcRtPEOsPFFWjobJEtfihkLCZCXZt/os3zf8nTxjVH3RvTSxjrCamJpbExGvYOF+tFHc3pA65qpdwPbzjohhew==", "dev": true, "peer": true, "bin": { diff --git a/package.json b/package.json index d31e71bd397db..3040f2fc33aac 100644 --- a/package.json +++ b/package.json @@ -10,11 +10,11 @@ "husky": "^9.0.1", "lint-staged": "^15.2.7", "prettier": "^3.3.2", - "prettier-plugin-rust": "^0.1.9", "prettier-plugin-sql-cst": "^0.11.5" }, "lint-staged": { - "*.{js,ts,php,sql,rs,md}": "prettier --write", - "*.py": "black -S" + "*.{js,ts,php,sql,md}": "prettier --write", + "*.py": "black -S", + "*.rs": "rustfmt" } } diff --git a/run_format.py b/run_format.py index f2f2f9abb4eef..0c72c6d53137f 100644 --- a/run_format.py +++ b/run_format.py @@ -330,11 +330,14 @@ def run(): os.system(f'npx clang-format -i --style=file "{path}"') # format with prettier - os.system('npx prettier --write "**/*.{js,ts,php,sql,rs,md}"') + os.system('npx prettier --write "**/*.{js,ts,php,sql,md}"') # format with gofmt os.system("gofmt -w .") + # format with rustfmt + os.system('find . -name "*.rs" -exec rustfmt {} \\;') + for path in paths: remove_header(path) for path in paths: diff --git a/solution/0000-0099/0002.Add Two Numbers/Solution.rs b/solution/0000-0099/0002.Add Two Numbers/Solution.rs index d5fb81cb7ec7b..d583581839409 100644 --- a/solution/0000-0099/0002.Add Two Numbers/Solution.rs +++ b/solution/0000-0099/0002.Add Two Numbers/Solution.rs @@ -17,7 +17,7 @@ impl Solution { pub fn add_two_numbers( mut l1: Option>, - mut l2: Option> + mut l2: Option>, ) -> Option> { let mut dummy = Some(Box::new(ListNode::new(0))); let mut cur = &mut dummy; diff --git a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.rs b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.rs index 2a2e7a71d6416..64e43f86096f5 100644 --- a/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.rs +++ b/solution/0000-0099/0003.Longest Substring Without Repeating Characters/Solution.rs @@ -5,8 +5,7 @@ impl Solution { let s = s.as_bytes(); let mut ss = HashSet::new(); let mut i = 0; - s - .iter() + s.iter() .map(|c| { while ss.contains(&c) { ss.remove(&s[i]); diff --git a/solution/0000-0099/0007.Reverse Integer/Solution.rs b/solution/0000-0099/0007.Reverse Integer/Solution.rs index 425ec8fe15e28..30689a4dfbf71 100644 --- a/solution/0000-0099/0007.Reverse Integer/Solution.rs +++ b/solution/0000-0099/0007.Reverse Integer/Solution.rs @@ -1,7 +1,14 @@ impl Solution { pub fn reverse(mut x: i32) -> i32 { let is_minus = x < 0; - match x.abs().to_string().chars().rev().collect::().parse::() { + match x + .abs() + .to_string() + .chars() + .rev() + .collect::() + .parse::() + { Ok(x) => x * (if is_minus { -1 } else { 1 }), Err(_) => 0, } diff --git a/solution/0000-0099/0010.Regular Expression Matching/Solution.rs b/solution/0000-0099/0010.Regular Expression Matching/Solution.rs index 350a0509f8d95..308f8ea782ac1 100644 --- a/solution/0000-0099/0010.Regular Expression Matching/Solution.rs +++ b/solution/0000-0099/0010.Regular Expression Matching/Solution.rs @@ -10,7 +10,7 @@ impl Solution { i: usize, j: usize, m: usize, - n: usize + n: usize, ) -> bool { if j >= n { return i == m; @@ -20,9 +20,8 @@ impl Solution { } let mut res = -1; if j + 1 < n && p[j + 1] == '*' { - if - dfs(s, p, f, i, j + 2, m, n) || - (i < m && (s[i] == p[j] || p[j] == '.') && dfs(s, p, f, i + 1, j, m, n)) + if dfs(s, p, f, i, j + 2, m, n) + || (i < m && (s[i] == p[j] || p[j] == '.') && dfs(s, p, f, i + 1, j, m, n)) { res = 1; } @@ -33,6 +32,14 @@ impl Solution { res == 1 } - dfs(&s.chars().collect(), &p.chars().collect(), &mut f, 0, 0, m, n) + dfs( + &s.chars().collect(), + &p.chars().collect(), + &mut f, + 0, + 0, + m, + n, + ) } } diff --git a/solution/0000-0099/0012.Integer to Roman/Solution.rs b/solution/0000-0099/0012.Integer to Roman/Solution.rs index 5abc6fbb56cb8..b8eeecffddb95 100644 --- a/solution/0000-0099/0012.Integer to Roman/Solution.rs +++ b/solution/0000-0099/0012.Integer to Roman/Solution.rs @@ -1,6 +1,8 @@ impl Solution { pub fn int_to_roman(num: i32) -> String { - let cs = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"]; + let cs = [ + "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I", + ]; let vs = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; let mut num = num; let mut ans = String::new(); diff --git a/solution/0000-0099/0013.Roman to Integer/Solution.rs b/solution/0000-0099/0013.Roman to Integer/Solution.rs index 453e8a16ee59c..f4d3086bd029a 100644 --- a/solution/0000-0099/0013.Roman to Integer/Solution.rs +++ b/solution/0000-0099/0013.Roman to Integer/Solution.rs @@ -1,8 +1,16 @@ impl Solution { pub fn roman_to_int(s: String) -> i32 { - let d = vec![('I', 1), ('V', 5), ('X', 10), ('L', 50), ('C', 100), ('D', 500), ('M', 1000)] - .into_iter() - .collect::>(); + let d = vec![ + ('I', 1), + ('V', 5), + ('X', 10), + ('L', 50), + ('C', 100), + ('D', 500), + ('M', 1000), + ] + .into_iter() + .collect::>(); let s: Vec = s.chars().collect(); let mut ans = 0; diff --git a/solution/0000-0099/0014.Longest Common Prefix/Solution.rs b/solution/0000-0099/0014.Longest Common Prefix/Solution.rs index 4d73b28f946a6..3846ae51e6375 100644 --- a/solution/0000-0099/0014.Longest Common Prefix/Solution.rs +++ b/solution/0000-0099/0014.Longest Common Prefix/Solution.rs @@ -1,10 +1,6 @@ impl Solution { pub fn longest_common_prefix(strs: Vec) -> String { - let mut len = strs - .iter() - .map(|s| s.len()) - .min() - .unwrap(); + let mut len = strs.iter().map(|s| s.len()).min().unwrap(); for i in (1..=len).rev() { let mut is_equal = true; let target = strs[0][0..i].to_string(); diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.rs b/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.rs index ef4c95dbafb61..481056c2ddb0a 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.rs +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/Solution.rs @@ -17,7 +17,7 @@ impl Solution { pub fn merge_two_lists( list1: Option>, - list2: Option> + list2: Option>, ) -> Option> { match (list1, list2) { (None, None) => None, diff --git a/solution/0000-0099/0021.Merge Two Sorted Lists/Solution2.rs b/solution/0000-0099/0021.Merge Two Sorted Lists/Solution2.rs index bd31db16f2fff..0ad255cf4fc88 100644 --- a/solution/0000-0099/0021.Merge Two Sorted Lists/Solution2.rs +++ b/solution/0000-0099/0021.Merge Two Sorted Lists/Solution2.rs @@ -17,7 +17,7 @@ impl Solution { pub fn merge_two_lists( mut list1: Option>, - mut list2: Option> + mut list2: Option>, ) -> Option> { let mut new_list = ListNode::new(0); let mut cur = &mut new_list; diff --git a/solution/0000-0099/0032.Longest Valid Parentheses/Solution.rs b/solution/0000-0099/0032.Longest Valid Parentheses/Solution.rs index 68aa7b6cd430c..9a476e04f10c0 100644 --- a/solution/0000-0099/0032.Longest Valid Parentheses/Solution.rs +++ b/solution/0000-0099/0032.Longest Valid Parentheses/Solution.rs @@ -3,25 +3,11 @@ impl Solution { let mut ans = 0; let mut f = vec![0; s.len() + 1]; for i in 2..=s.len() { - if - s - .chars() - .nth(i - 1) - .unwrap() == ')' - { - if - s - .chars() - .nth(i - 2) - .unwrap() == '(' - { + if s.chars().nth(i - 1).unwrap() == ')' { + if s.chars().nth(i - 2).unwrap() == '(' { f[i] = f[i - 2] + 2; - } else if - (i as i32) - f[i - 1] - 1 > 0 && - s - .chars() - .nth(i - (f[i - 1] as usize) - 2) - .unwrap() == '(' + } else if (i as i32) - f[i - 1] - 1 > 0 + && s.chars().nth(i - (f[i - 1] as usize) - 2).unwrap() == '(' { f[i] = f[i - 1] + 2 + f[i - (f[i - 1] as usize) - 2]; } diff --git a/solution/0000-0099/0041.First Missing Positive/Solution.rs b/solution/0000-0099/0041.First Missing Positive/Solution.rs index d9bc29d11be9b..ba6dfba223149 100644 --- a/solution/0000-0099/0041.First Missing Positive/Solution.rs +++ b/solution/0000-0099/0041.First Missing Positive/Solution.rs @@ -10,12 +10,11 @@ impl Solution { nums.swap(i, j as usize); } } - ( - nums - .iter() - .enumerate() - .position(|(i, &v)| (v as usize) != i + 1) - .unwrap_or(n) as i32 - ) + 1 + (nums + .iter() + .enumerate() + .position(|(i, &v)| (v as usize) != i + 1) + .unwrap_or(n) as i32) + + 1 } } diff --git a/solution/0000-0099/0049.Group Anagrams/Solution.rs b/solution/0000-0099/0049.Group Anagrams/Solution.rs index ca7195d109292..a3e87c12792fc 100644 --- a/solution/0000-0099/0049.Group Anagrams/Solution.rs +++ b/solution/0000-0099/0049.Group Anagrams/Solution.rs @@ -12,8 +12,6 @@ impl Solution { let val = map.entry(key).or_insert(vec![]); val.push(s); } - map.into_iter() - .map(|(_, v)| v) - .collect() + map.into_iter().map(|(_, v)| v).collect() } } diff --git a/solution/0000-0099/0065.Valid Number/Solution.rs b/solution/0000-0099/0065.Valid Number/Solution.rs index f4dc3fbc62698..86359d8e4cdc3 100644 --- a/solution/0000-0099/0065.Valid Number/Solution.rs +++ b/solution/0000-0099/0065.Valid Number/Solution.rs @@ -12,10 +12,13 @@ impl Solution { } } if let Some(x) = s.chars().nth(i) { - if - x == '.' && - (i + 1 == n || - (if let Some(m) = s.chars().nth(i + 1) { m == 'e' || m == 'E' } else { false })) + if x == '.' + && (i + 1 == n + || (if let Some(m) = s.chars().nth(i + 1) { + m == 'e' || m == 'E' + } else { + false + })) { return false; } diff --git a/solution/0000-0099/0079.Word Search/Solution.rs b/solution/0000-0099/0079.Word Search/Solution.rs index 38d4cc5f3c39a..41b900326809b 100644 --- a/solution/0000-0099/0079.Word Search/Solution.rs +++ b/solution/0000-0099/0079.Word Search/Solution.rs @@ -5,7 +5,7 @@ impl Solution { c: usize, word: &[u8], board: &Vec>, - vis: &mut Vec> + vis: &mut Vec>, ) -> bool { if (board[i][j] as u8) != word[c] { return false; @@ -14,12 +14,7 @@ impl Solution { return true; } vis[i][j] = true; - let dirs = [ - [-1, 0], - [0, -1], - [1, 0], - [0, 1], - ]; + let dirs = [[-1, 0], [0, -1], [1, 0], [0, 1]]; for [x, y] in dirs.into_iter() { let i = x + (i as i32); let j = y + (j as i32); diff --git a/solution/0000-0099/0092.Reverse Linked List II/Solution.rs b/solution/0000-0099/0092.Reverse Linked List II/Solution.rs index 1678ffa65a60d..7e6da23757b1b 100644 --- a/solution/0000-0099/0092.Reverse Linked List II/Solution.rs +++ b/solution/0000-0099/0092.Reverse Linked List II/Solution.rs @@ -18,7 +18,7 @@ impl Solution { pub fn reverse_between( head: Option>, left: i32, - right: i32 + right: i32, ) -> Option> { let mut dummy = Some(Box::new(ListNode { val: 0, next: head })); let mut pre = &mut dummy; diff --git a/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution.rs b/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution.rs index f447d4df7cfb1..32ed7a32af425 100644 --- a/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution.rs +++ b/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, ans: &mut Vec) { if root.is_none() { diff --git a/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution2.rs b/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution2.rs index e4979fb3e38a1..b7ef1a87dc2fb 100644 --- a/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution2.rs +++ b/solution/0000-0099/0094.Binary Tree Inorder Traversal/Solution2.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn inorder_traversal(mut root: Option>>) -> Vec { let mut ans = vec![]; diff --git a/solution/0000-0099/0095.Unique Binary Search Trees II/Solution.rs b/solution/0000-0099/0095.Unique Binary Search Trees II/Solution.rs index c2772b463d772..ce55b3244cef7 100644 --- a/solution/0000-0099/0095.Unique Binary Search Trees II/Solution.rs +++ b/solution/0000-0099/0095.Unique Binary Search Trees II/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn generate_trees(n: i32) -> Vec>>> { Self::dfs(1, n) @@ -34,17 +34,11 @@ impl Solution { let right = Self::dfs(v + 1, j); for l in &left { for r in &right { - ans.push( - Some( - Rc::new( - RefCell::new(TreeNode { - val: v, - left: l.clone(), - right: r.clone(), - }) - ) - ) - ); + ans.push(Some(Rc::new(RefCell::new(TreeNode { + val: v, + left: l.clone(), + right: r.clone(), + })))); } } } diff --git a/solution/0000-0099/0097.Interleaving String/Solution.rs b/solution/0000-0099/0097.Interleaving String/Solution.rs index 419d697d533cf..f2dfc119774e8 100644 --- a/solution/0000-0099/0097.Interleaving String/Solution.rs +++ b/solution/0000-0099/0097.Interleaving String/Solution.rs @@ -18,7 +18,7 @@ impl Solution { 0, &s1.chars().collect(), &s2.chars().collect(), - &s3.chars().collect() + &s3.chars().collect(), ) } @@ -31,7 +31,7 @@ impl Solution { j: usize, s1: &Vec, s2: &Vec, - s3: &Vec + s3: &Vec, ) -> bool { if i >= n && j >= m { return true; @@ -51,11 +51,10 @@ impl Solution { } // If the first approach does not succeed, let's then try `s2` - if - record[i][j] == 0 && - j < m && - s2[j] == s3[k] && - Self::dfs(record, n, m, i, j + 1, s1, s2, s3) + if record[i][j] == 0 + && j < m + && s2[j] == s3[k] + && Self::dfs(record, n, m, i, j + 1, s1, s2, s3) { record[i][j] = 1; } diff --git a/solution/0000-0099/0098.Validate Binary Search Tree/Solution.rs b/solution/0000-0099/0098.Validate Binary Search Tree/Solution.rs index e1cdfad146d8b..2de4f9512578e 100644 --- a/solution/0000-0099/0098.Validate Binary Search Tree/Solution.rs +++ b/solution/0000-0099/0098.Validate Binary Search Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, prev: &mut Option) -> bool { if root.is_none() { diff --git a/solution/0100-0199/0100.Same Tree/Solution.rs b/solution/0100-0199/0100.Same Tree/Solution.rs index ecc58869aff89..ab3b98b9134d6 100644 --- a/solution/0100-0199/0100.Same Tree/Solution.rs +++ b/solution/0100-0199/0100.Same Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(p: &Option>>, q: &Option>>) -> bool { if p.is_none() && q.is_none() { @@ -33,7 +33,7 @@ impl Solution { pub fn is_same_tree( p: Option>>, - q: Option>> + q: Option>>, ) -> bool { Self::dfs(&p, &q) } diff --git a/solution/0100-0199/0100.Same Tree/Solution2.rs b/solution/0100-0199/0100.Same Tree/Solution2.rs index 992b3b21e84cf..282179eaf64c4 100644 --- a/solution/0100-0199/0100.Same Tree/Solution2.rs +++ b/solution/0100-0199/0100.Same Tree/Solution2.rs @@ -16,13 +16,13 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn is_same_tree( mut p: Option>>, - mut q: Option>> + mut q: Option>>, ) -> bool { let mut queue = VecDeque::new(); if p.is_some() { diff --git a/solution/0100-0199/0101.Symmetric Tree/Solution.rs b/solution/0100-0199/0101.Symmetric Tree/Solution.rs index 6efb004cc48a5..831f5da4e0d8c 100644 --- a/solution/0100-0199/0101.Symmetric Tree/Solution.rs +++ b/solution/0100-0199/0101.Symmetric Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root1: &Option>>, root2: &Option>>) -> bool { if root1.is_none() && root2.is_none() { @@ -28,9 +28,9 @@ impl Solution { } let node1 = root1.as_ref().unwrap().borrow(); let node2 = root2.as_ref().unwrap().borrow(); - node1.val == node2.val && - Self::dfs(&node1.left, &node2.right) && - Self::dfs(&node1.right, &node2.left) + node1.val == node2.val + && Self::dfs(&node1.left, &node2.right) + && Self::dfs(&node1.right, &node2.left) } pub fn is_symmetric(root: Option>>) -> bool { diff --git a/solution/0100-0199/0101.Symmetric Tree/Solution2.rs b/solution/0100-0199/0101.Symmetric Tree/Solution2.rs index 3bdcaffe5ae13..a1fb59abbc400 100644 --- a/solution/0100-0199/0101.Symmetric Tree/Solution2.rs +++ b/solution/0100-0199/0101.Symmetric Tree/Solution2.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn is_symmetric(root: Option>>) -> bool { let root = root.unwrap(); diff --git a/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.rs b/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.rs index d4854906a0fea..aeedabcd68a0a 100644 --- a/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.rs +++ b/solution/0100-0199/0102.Binary Tree Level Order Traversal/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; -use std::collections::{ VecDeque }; +use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn level_order(root: Option>>) -> Vec> { let mut ans = Vec::new(); diff --git a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.rs b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.rs index 82dc13ef15631..3a50abb0d06dd 100644 --- a/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.rs +++ b/solution/0100-0199/0103.Binary Tree Zigzag Level Order Traversal/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn zigzag_level_order(root: Option>>) -> Vec> { let mut ans = Vec::new(); diff --git a/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.rs b/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.rs index 5ec0b765fe1b2..c4ad64e68e7f5 100644 --- a/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.rs +++ b/solution/0100-0199/0104.Maximum Depth of Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>) -> i32 { if root.is_none() { diff --git a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.rs b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.rs index 0fbbf24b5efd7..ef38fe420e192 100644 --- a/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.rs +++ b/solution/0100-0199/0105.Construct Binary Tree from Preorder and Inorder Traversal/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; impl Solution { pub fn build_tree(preorder: Vec, inorder: Vec) -> Option>> { let mut d = HashMap::new(); @@ -33,7 +33,7 @@ impl Solution { d: &HashMap, i: usize, j: usize, - n: usize + n: usize, ) -> Option>> { if n <= 0 { return None; diff --git a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.rs b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.rs index a7075a18dbd00..78efc3ec6ab21 100644 --- a/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.rs +++ b/solution/0100-0199/0106.Construct Binary Tree from Inorder and Postorder Traversal/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; impl Solution { pub fn build_tree(inorder: Vec, postorder: Vec) -> Option>> { let n = inorder.len(); @@ -31,7 +31,7 @@ impl Solution { d: &HashMap, i: usize, j: usize, - n: usize + n: usize, ) -> Option>> { if n <= 0 { return None; diff --git a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.rs b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.rs index 9891165601e99..878d1bf663cce 100644 --- a/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.rs +++ b/solution/0100-0199/0107.Binary Tree Level Order Traversal II/Solution.rs @@ -16,7 +16,7 @@ // } // } // } -use std::{ rc::Rc, cell::RefCell, collections::VecDeque }; +use std::{cell::RefCell, collections::VecDeque, rc::Rc}; impl Solution { pub fn level_order_bottom(root: Option>>) -> Vec> { let mut ans = Vec::new(); diff --git a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.rs b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.rs index 8c1898c14351d..2c98083931569 100644 --- a/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.rs +++ b/solution/0100-0199/0108.Convert Sorted Array to Binary Search Tree/Solution.rs @@ -16,23 +16,19 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn to_bst(nums: &Vec, start: usize, end: usize) -> Option>> { if start >= end { return None; } let mid = start + (end - start) / 2; - Some( - Rc::new( - RefCell::new(TreeNode { - val: nums[mid], - left: Self::to_bst(nums, start, mid), - right: Self::to_bst(nums, mid + 1, end), - }) - ) - ) + Some(Rc::new(RefCell::new(TreeNode { + val: nums[mid], + left: Self::to_bst(nums, start, mid), + right: Self::to_bst(nums, mid + 1, end), + }))) } pub fn sorted_array_to_bst(nums: Vec) -> Option>> { diff --git a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/Solution.rs b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/Solution.rs index cb37a4deb5439..2d96335ac0ffb 100644 --- a/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/Solution.rs +++ b/solution/0100-0199/0109.Convert Sorted List to Binary Search Tree/Solution.rs @@ -32,23 +32,19 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn build(vals: &Vec, start: usize, end: usize) -> Option>> { if start == end { return None; } let mid = (start + end) >> 1; - Some( - Rc::new( - RefCell::new(TreeNode { - val: vals[mid], - left: Self::build(vals, start, mid), - right: Self::build(vals, mid + 1, end), - }) - ) - ) + Some(Rc::new(RefCell::new(TreeNode { + val: vals[mid], + left: Self::build(vals, start, mid), + right: Self::build(vals, mid + 1, end), + }))) } pub fn sorted_list_to_bst(head: Option>) -> Option>> { diff --git a/solution/0100-0199/0110.Balanced Binary Tree/Solution.rs b/solution/0100-0199/0110.Balanced Binary Tree/Solution.rs index 84ed51521c70f..741e99ed6562b 100644 --- a/solution/0100-0199/0110.Balanced Binary Tree/Solution.rs +++ b/solution/0100-0199/0110.Balanced Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn is_balanced(root: Option>>) -> bool { Self::dfs(&root) > -1 diff --git a/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.rs b/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.rs index 1e70d1e1b5277..1678e4fde1b80 100644 --- a/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.rs +++ b/solution/0100-0199/0111.Minimum Depth of Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>) -> i32 { if root.is_none() { diff --git a/solution/0100-0199/0112.Path Sum/Solution.rs b/solution/0100-0199/0112.Path Sum/Solution.rs index a43a5bff6b471..703624b03431f 100644 --- a/solution/0100-0199/0112.Path Sum/Solution.rs +++ b/solution/0100-0199/0112.Path Sum/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn has_path_sum(root: Option>>, target_sum: i32) -> bool { match root { @@ -29,8 +29,8 @@ impl Solution { return target_sum - node.val == 0; } let val = node.val; - Self::has_path_sum(node.left.take(), target_sum - val) || - Self::has_path_sum(node.right.take(), target_sum - val) + Self::has_path_sum(node.left.take(), target_sum - val) + || Self::has_path_sum(node.right.take(), target_sum - val) } } } diff --git a/solution/0100-0199/0113.Path Sum II/Solution.rs b/solution/0100-0199/0113.Path Sum II/Solution.rs index 37d4acd5f5960..15a70800af544 100644 --- a/solution/0100-0199/0113.Path Sum II/Solution.rs +++ b/solution/0100-0199/0113.Path Sum II/Solution.rs @@ -16,14 +16,14 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs( root: Option>>, paths: &mut Vec, mut target_sum: i32, - res: &mut Vec> + res: &mut Vec>, ) { if let Some(node) = root { let mut node = node.borrow_mut(); diff --git a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/Solution.rs b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/Solution.rs index 54e3a815dce4d..f7d194e0a3e9d 100644 --- a/solution/0100-0199/0114.Flatten Binary Tree to Linked List/Solution.rs +++ b/solution/0100-0199/0114.Flatten Binary Tree to Linked List/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { #[allow(dead_code)] pub fn flatten(root: &mut Option>>) { @@ -38,7 +38,7 @@ impl Solution { #[allow(dead_code)] fn pre_order_traverse( v: &mut Vec>>>, - root: &Option>> + root: &Option>>, ) { if root.is_none() { return; diff --git a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.rs b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.rs index 5b24aa51d2e32..56f870e933db6 100644 --- a/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.rs +++ b/solution/0100-0199/0124.Binary Tree Maximum Path Sum/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, res: &mut i32) -> i32 { if root.is_none() { diff --git a/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.rs b/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.rs index 8bb565180bbcf..413c0b117b4d4 100644 --- a/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.rs +++ b/solution/0100-0199/0129.Sum Root to Leaf Numbers/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(node: &Option>>, mut num: i32) -> i32 { if node.is_none() { diff --git a/solution/0100-0199/0130.Surrounded Regions/Solution.rs b/solution/0100-0199/0130.Surrounded Regions/Solution.rs index 3ba59cf346749..6cf4268867e60 100644 --- a/solution/0100-0199/0130.Surrounded Regions/Solution.rs +++ b/solution/0100-0199/0130.Surrounded Regions/Solution.rs @@ -10,7 +10,7 @@ impl Solution { j: usize, dirs: &Vec, m: usize, - n: usize + n: usize, ) { if i >= 0 && i < m && j >= 0 && j < n && board[i][j] == 'O' { board[i][j] = '.'; @@ -21,7 +21,7 @@ impl Solution { ((j as i32) + dirs[k + 1]) as usize, dirs, m, - n + n, ); } } diff --git a/solution/0100-0199/0136.Single Number/Solution.rs b/solution/0100-0199/0136.Single Number/Solution.rs index 92067bc24963a..7285716dc4d1d 100644 --- a/solution/0100-0199/0136.Single Number/Solution.rs +++ b/solution/0100-0199/0136.Single Number/Solution.rs @@ -1,7 +1,5 @@ impl Solution { pub fn single_number(nums: Vec) -> i32 { - nums.into_iter() - .reduce(|r, v| r ^ v) - .unwrap() + nums.into_iter().reduce(|r, v| r ^ v).unwrap() } } diff --git a/solution/0100-0199/0137.Single Number II/Solution.rs b/solution/0100-0199/0137.Single Number II/Solution.rs index 392656403e206..c5ea58835368b 100644 --- a/solution/0100-0199/0137.Single Number II/Solution.rs +++ b/solution/0100-0199/0137.Single Number II/Solution.rs @@ -2,10 +2,7 @@ impl Solution { pub fn single_number(nums: Vec) -> i32 { let mut ans = 0; for i in 0..32 { - let count = nums - .iter() - .map(|v| (v >> i) & 1) - .sum::(); + let count = nums.iter().map(|v| (v >> i) & 1).sum::(); ans |= count % 3 << i; } ans diff --git a/solution/0100-0199/0143.Reorder List/Solution.rs b/solution/0100-0199/0143.Reorder List/Solution.rs index 1c58aa53b92f9..63b957184e58b 100644 --- a/solution/0100-0199/0143.Reorder List/Solution.rs +++ b/solution/0100-0199/0143.Reorder List/Solution.rs @@ -27,7 +27,11 @@ impl Solution { } let mut flag = false; while !deque.is_empty() { - *tail = if flag { deque.pop_front().unwrap() } else { deque.pop_back().unwrap() }; + *tail = if flag { + deque.pop_front().unwrap() + } else { + deque.pop_back().unwrap() + }; tail = &mut tail.as_mut().unwrap().next; flag = !flag; } diff --git a/solution/0100-0199/0144.Binary Tree Preorder Traversal/Solution.rs b/solution/0100-0199/0144.Binary Tree Preorder Traversal/Solution.rs index 10a576ba529d2..e91d2d7a6acfb 100644 --- a/solution/0100-0199/0144.Binary Tree Preorder Traversal/Solution.rs +++ b/solution/0100-0199/0144.Binary Tree Preorder Traversal/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, ans: &mut Vec) { if root.is_none() { diff --git a/solution/0100-0199/0145.Binary Tree Postorder Traversal/Solution.rs b/solution/0100-0199/0145.Binary Tree Postorder Traversal/Solution.rs index c8500d43e8507..bbcc601833900 100644 --- a/solution/0100-0199/0145.Binary Tree Postorder Traversal/Solution.rs +++ b/solution/0100-0199/0145.Binary Tree Postorder Traversal/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, ans: &mut Vec) { if root.is_none() { diff --git a/solution/0100-0199/0146.LRU Cache/README.md b/solution/0100-0199/0146.LRU Cache/README.md index a5bf52d5e73f2..ce93f6c338ef2 100644 --- a/solution/0100-0199/0146.LRU Cache/README.md +++ b/solution/0100-0199/0146.LRU Cache/README.md @@ -582,12 +582,7 @@ impl LRUCache { None => None, } } -}/** - * Your LRUCache object will be instantiated and called as such: - * let obj = LRUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} ``` #### C# diff --git a/solution/0100-0199/0146.LRU Cache/README_EN.md b/solution/0100-0199/0146.LRU Cache/README_EN.md index ce8f5ab122de7..719886f5ead4c 100644 --- a/solution/0100-0199/0146.LRU Cache/README_EN.md +++ b/solution/0100-0199/0146.LRU Cache/README_EN.md @@ -576,12 +576,7 @@ impl LRUCache { None => None, } } -}/** - * Your LRUCache object will be instantiated and called as such: - * let obj = LRUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} ``` #### C# diff --git a/solution/0100-0199/0146.LRU Cache/Solution.rs b/solution/0100-0199/0146.LRU Cache/Solution.rs index 76b8fecb7769d..c02f601eb4a60 100644 --- a/solution/0100-0199/0146.LRU Cache/Solution.rs +++ b/solution/0100-0199/0146.LRU Cache/Solution.rs @@ -120,9 +120,4 @@ impl LRUCache { None => None, } } -}/** - * Your LRUCache object will be instantiated and called as such: - * let obj = LRUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} diff --git a/solution/0100-0199/0155.Min Stack/README.md b/solution/0100-0199/0155.Min Stack/README.md index bcd38445f1b9a..c03b30edd785e 100644 --- a/solution/0100-0199/0155.Min Stack/README.md +++ b/solution/0100-0199/0155.Min Stack/README.md @@ -314,14 +314,7 @@ impl MinStack { fn get_min(&self) -> i32 { *self.stk2.back().unwrap() } -}/** - * Your MinStack object will be instantiated and called as such: - * let obj = MinStack::new(); - * obj.push(x); - * obj.pop(); - * let ret_3: i32 = obj.top(); - * let ret_4: i32 = obj.get_min(); - */ +} ``` #### JavaScript diff --git a/solution/0100-0199/0155.Min Stack/README_EN.md b/solution/0100-0199/0155.Min Stack/README_EN.md index 1695dd1060207..af7858b95ccca 100644 --- a/solution/0100-0199/0155.Min Stack/README_EN.md +++ b/solution/0100-0199/0155.Min Stack/README_EN.md @@ -305,14 +305,7 @@ impl MinStack { fn get_min(&self) -> i32 { *self.stk2.back().unwrap() } -}/** - * Your MinStack object will be instantiated and called as such: - * let obj = MinStack::new(); - * obj.push(x); - * obj.pop(); - * let ret_3: i32 = obj.top(); - * let ret_4: i32 = obj.get_min(); - */ +} ``` #### JavaScript diff --git a/solution/0100-0199/0155.Min Stack/Solution.rs b/solution/0100-0199/0155.Min Stack/Solution.rs index 9f43fb8a60104..e1819a125a4c7 100644 --- a/solution/0100-0199/0155.Min Stack/Solution.rs +++ b/solution/0100-0199/0155.Min Stack/Solution.rs @@ -10,7 +10,10 @@ struct MinStack { */ impl MinStack { fn new() -> Self { - Self { stk1: VecDeque::new(), stk2: VecDeque::new() } + Self { + stk1: VecDeque::new(), + stk2: VecDeque::new(), + } } fn push(&mut self, x: i32) { @@ -34,11 +37,4 @@ impl MinStack { fn get_min(&self) -> i32 { *self.stk2.back().unwrap() } -}/** - * Your MinStack object will be instantiated and called as such: - * let obj = MinStack::new(); - * obj.push(x); - * obj.pop(); - * let ret_3: i32 = obj.top(); - * let ret_4: i32 = obj.get_min(); - */ +} diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/README.md b/solution/0100-0199/0173.Binary Search Tree Iterator/README.md index b6f13f2d53221..111b7b4b8f68e 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/README.md +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/README.md @@ -387,12 +387,7 @@ impl BSTIterator { fn has_next(&self) -> bool { self.index != self.vals.len() } -}/** - * Your BSTIterator object will be instantiated and called as such: - * let obj = BSTIterator::new(root); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} ``` #### JavaScript @@ -703,12 +698,7 @@ impl BSTIterator { fn has_next(&self) -> bool { self.stack.len() != 0 } -}/** - * Your BSTIterator object will be instantiated and called as such: - * let obj = BSTIterator::new(root); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} ``` diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md b/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md index d78520b80b348..47ac70c605db9 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/README_EN.md @@ -376,12 +376,7 @@ impl BSTIterator { fn has_next(&self) -> bool { self.index != self.vals.len() } -}/** - * Your BSTIterator object will be instantiated and called as such: - * let obj = BSTIterator::new(root); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} ``` #### JavaScript @@ -688,12 +683,7 @@ impl BSTIterator { fn has_next(&self) -> bool { self.stack.len() != 0 } -}/** - * Your BSTIterator object will be instantiated and called as such: - * let obj = BSTIterator::new(root); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} ``` diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/Solution.rs b/solution/0100-0199/0173.Binary Search Tree Iterator/Solution.rs index fac969c93c207..72b45ef46d027 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/Solution.rs +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/Solution.rs @@ -21,8 +21,8 @@ struct BSTIterator { index: usize, } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. @@ -40,10 +40,7 @@ impl BSTIterator { fn new(root: Option>>) -> Self { let mut vals = vec![]; Self::inorder(&root, &mut vals); - BSTIterator { - vals, - index: 0, - } + BSTIterator { vals, index: 0 } } fn next(&mut self) -> i32 { @@ -54,9 +51,4 @@ impl BSTIterator { fn has_next(&self) -> bool { self.index != self.vals.len() } -}/** - * Your BSTIterator object will be instantiated and called as such: - * let obj = BSTIterator::new(root); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} diff --git a/solution/0100-0199/0173.Binary Search Tree Iterator/Solution2.rs b/solution/0100-0199/0173.Binary Search Tree Iterator/Solution2.rs index 6fb31ff8823d8..da201e2d0ade3 100644 --- a/solution/0100-0199/0173.Binary Search Tree Iterator/Solution2.rs +++ b/solution/0100-0199/0173.Binary Search Tree Iterator/Solution2.rs @@ -20,8 +20,8 @@ struct BSTIterator { stack: Vec>>>, } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; /** * `&self` means the method takes an immutable reference. * If you need a mutable reference, change it to `&mut self` instead. @@ -29,7 +29,7 @@ use std::cell::RefCell; impl BSTIterator { fn dfs( mut root: Option>>, - stack: &mut Vec>>> + stack: &mut Vec>>>, ) { if root.is_some() { let left = root.as_mut().unwrap().borrow_mut().left.take(); @@ -56,9 +56,4 @@ impl BSTIterator { fn has_next(&self) -> bool { self.stack.len() != 0 } -}/** - * Your BSTIterator object will be instantiated and called as such: - * let obj = BSTIterator::new(root); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} diff --git a/solution/0100-0199/0199.Binary Tree Right Side View/Solution.rs b/solution/0100-0199/0199.Binary Tree Right Side View/Solution.rs index 3718395429249..a92b5c2f5a8a9 100644 --- a/solution/0100-0199/0199.Binary Tree Right Side View/Solution.rs +++ b/solution/0100-0199/0199.Binary Tree Right Side View/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn right_side_view(root: Option>>) -> Vec { let mut res = vec![]; diff --git a/solution/0200-0299/0200.Number of Islands/Solution.rs b/solution/0200-0299/0200.Number of Islands/Solution.rs index 358ee6a149f86..ab499f9cc8a27 100644 --- a/solution/0200-0299/0200.Number of Islands/Solution.rs +++ b/solution/0200-0299/0200.Number of Islands/Solution.rs @@ -7,12 +7,11 @@ impl Solution { for k in 0..4 { let x = (i as i32) + DIRS[k]; let y = (j as i32) + DIRS[k + 1]; - if - x >= 0 && - (x as usize) < grid.len() && - y >= 0 && - (y as usize) < grid[0].len() && - grid[x as usize][y as usize] == '1' + if x >= 0 + && (x as usize) < grid.len() + && y >= 0 + && (y as usize) < grid[0].len() + && grid[x as usize][y as usize] == '1' { dfs(grid, x as usize, y as usize); } diff --git a/solution/0200-0299/0200.Number of Islands/Solution2.rs b/solution/0200-0299/0200.Number of Islands/Solution2.rs index b85564f64b07b..9bd5d8a2a22f9 100644 --- a/solution/0200-0299/0200.Number of Islands/Solution2.rs +++ b/solution/0200-0299/0200.Number of Islands/Solution2.rs @@ -12,12 +12,11 @@ impl Solution { for k in 0..4 { let x = (i as i32) + DIRS[k]; let y = (j as i32) + DIRS[k + 1]; - if - x >= 0 && - (x as usize) < grid.len() && - y >= 0 && - (y as usize) < grid[0].len() && - grid[x as usize][y as usize] == '1' + if x >= 0 + && (x as usize) < grid.len() + && y >= 0 + && (y as usize) < grid[0].len() + && grid[x as usize][y as usize] == '1' { grid[x as usize][y as usize] = '0'; queue.push_back((x as usize, y as usize)); diff --git a/solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.rs b/solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.rs index 90d2217a47ef1..d0fec967b4cbc 100644 --- a/solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.rs +++ b/solution/0200-0299/0208.Implement Trie (Prefix Tree)/Solution.rs @@ -1,4 +1,4 @@ -use std::{ rc::Rc, cell::RefCell, collections::HashMap }; +use std::{cell::RefCell, collections::HashMap, rc::Rc}; struct TrieNode { pub val: Option, @@ -47,7 +47,9 @@ impl Trie { for c in &char_vec { if !root.borrow().child.contains_key(c) { // We need to manually create the entry - root.borrow_mut().child.insert(*c, Rc::new(RefCell::new(TrieNode::new()))); + root.borrow_mut() + .child + .insert(*c, Rc::new(RefCell::new(TrieNode::new()))); } // Get the child node let root_clone = Rc::clone(root.borrow().child.get(c).unwrap()); diff --git a/solution/0200-0299/0216.Combination Sum III/Solution.rs b/solution/0200-0299/0216.Combination Sum III/Solution.rs index 78a60f424d22f..95f113868bfa3 100644 --- a/solution/0200-0299/0216.Combination Sum III/Solution.rs +++ b/solution/0200-0299/0216.Combination Sum III/Solution.rs @@ -16,7 +16,7 @@ impl Solution { cur_sum: i32, cur_vec: &mut Vec, candidates: &Vec, - ans: &mut Vec> + ans: &mut Vec>, ) { if cur_sum > target || cur_vec.len() > (length as usize) { // No answer for this @@ -29,7 +29,15 @@ impl Solution { } for i in cur_index..candidates.len() { cur_vec.push(candidates[i]); - Self::dfs(target, length, i + 1, cur_sum + candidates[i], cur_vec, candidates, ans); + Self::dfs( + target, + length, + i + 1, + cur_sum + candidates[i], + cur_vec, + candidates, + ans, + ); cur_vec.pop().unwrap(); } } diff --git a/solution/0200-0299/0222.Count Complete Tree Nodes/Solution.rs b/solution/0200-0299/0222.Count Complete Tree Nodes/Solution.rs index c6c1f0d5af102..9cc7d68b0984b 100644 --- a/solution/0200-0299/0222.Count Complete Tree Nodes/Solution.rs +++ b/solution/0200-0299/0222.Count Complete Tree Nodes/Solution.rs @@ -18,6 +18,10 @@ impl Solution { } fn depth(root: &Option>>) -> i32 { - if let Some(node) = root { Self::depth(&node.borrow().left) + 1 } else { 0 } + if let Some(node) = root { + Self::depth(&node.borrow().left) + 1 + } else { + 0 + } } } diff --git a/solution/0200-0299/0226.Invert Binary Tree/Solution.rs b/solution/0200-0299/0226.Invert Binary Tree/Solution.rs index 4122b5f8a953e..58f8a78966e30 100644 --- a/solution/0200-0299/0226.Invert Binary Tree/Solution.rs +++ b/solution/0200-0299/0226.Invert Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { #[allow(dead_code)] pub fn invert_tree(root: Option>>) -> Option>> { diff --git a/solution/0200-0299/0230.Kth Smallest Element in a BST/Solution.rs b/solution/0200-0299/0230.Kth Smallest Element in a BST/Solution.rs index dfaabf8de28b1..6bd4e61e9e19b 100644 --- a/solution/0200-0299/0230.Kth Smallest Element in a BST/Solution.rs +++ b/solution/0200-0299/0230.Kth Smallest Element in a BST/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: Option>>, res: &mut Vec, k: usize) { if let Some(node) = root { diff --git a/solution/0200-0299/0232.Implement Queue using Stacks/README.md b/solution/0200-0299/0232.Implement Queue using Stacks/README.md index 7ebcdb3ffad05..1b39c1023ac26 100644 --- a/solution/0200-0299/0232.Implement Queue using Stacks/README.md +++ b/solution/0200-0299/0232.Implement Queue using Stacks/README.md @@ -375,14 +375,7 @@ impl MyQueue { } } } -}/** - * Your MyQueue object will be instantiated and called as such: - * let obj = MyQueue::new(); - * obj.push(x); - * let ret_2: i32 = obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.empty(); - */ +} ``` diff --git a/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md b/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md index fab409a98d5fc..87ce266329487 100644 --- a/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md +++ b/solution/0200-0299/0232.Implement Queue using Stacks/README_EN.md @@ -365,14 +365,7 @@ impl MyQueue { } } } -}/** - * Your MyQueue object will be instantiated and called as such: - * let obj = MyQueue::new(); - * obj.push(x); - * let ret_2: i32 = obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.empty(); - */ +} ``` diff --git a/solution/0200-0299/0232.Implement Queue using Stacks/Solution.rs b/solution/0200-0299/0232.Implement Queue using Stacks/Solution.rs index a7c5fb57a4170..a08427c055f69 100644 --- a/solution/0200-0299/0232.Implement Queue using Stacks/Solution.rs +++ b/solution/0200-0299/0232.Implement Queue using Stacks/Solution.rs @@ -38,11 +38,4 @@ impl MyQueue { } } } -}/** - * Your MyQueue object will be instantiated and called as such: - * let obj = MyQueue::new(); - * obj.push(x); - * let ret_2: i32 = obj.pop(); - * let ret_3: i32 = obj.peek(); - * let ret_4: bool = obj.empty(); - */ +} diff --git a/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.rs b/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.rs index 465416180ebeb..3313fe90c814e 100644 --- a/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.rs +++ b/solution/0200-0299/0236.Lowest Common Ancestor of a Binary Tree/Solution.rs @@ -16,13 +16,13 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn lowest_common_ancestor( root: Option>>, p: Option>>, - q: Option>> + q: Option>>, ) -> Option>> { if root.is_none() || root == p || root == q { return root; @@ -30,12 +30,12 @@ impl Solution { let left = Self::lowest_common_ancestor( root.as_ref().unwrap().borrow().left.clone(), p.clone(), - q.clone() + q.clone(), ); let right = Self::lowest_common_ancestor( root.as_ref().unwrap().borrow().right.clone(), p.clone(), - q.clone() + q.clone(), ); if left.is_some() && right.is_some() { return root; diff --git a/solution/0200-0299/0252.Meeting Rooms/Solution.rs b/solution/0200-0299/0252.Meeting Rooms/Solution.rs index 8c313dc9e9440..1ee4bd2d2cc4a 100644 --- a/solution/0200-0299/0252.Meeting Rooms/Solution.rs +++ b/solution/0200-0299/0252.Meeting Rooms/Solution.rs @@ -8,7 +8,7 @@ impl Solution { let mut intervals = intervals; // Sort the intervals vector - intervals.sort_by(|lhs, rhs| { lhs[0].cmp(&rhs[0]) }); + intervals.sort_by(|lhs, rhs| lhs[0].cmp(&rhs[0])); let mut end = -1; diff --git a/solution/0200-0299/0253.Meeting Rooms II/Solution.rs b/solution/0200-0299/0253.Meeting Rooms II/Solution.rs index a79e5216a86b1..ad9cd0a9b24ec 100644 --- a/solution/0200-0299/0253.Meeting Rooms II/Solution.rs +++ b/solution/0200-0299/0253.Meeting Rooms II/Solution.rs @@ -1,4 +1,4 @@ -use std::{ collections::BinaryHeap, cmp::Reverse }; +use std::{cmp::Reverse, collections::BinaryHeap}; impl Solution { #[allow(dead_code)] @@ -9,7 +9,7 @@ impl Solution { let n = intervals.len(); // Let's first sort the intervals vector - intervals.sort_by(|lhs, rhs| { lhs[0].cmp(&rhs[0]) }); + intervals.sort_by(|lhs, rhs| lhs[0].cmp(&rhs[0])); // Push the first end time to the heap pq.push(Reverse(intervals[0][1])); diff --git a/solution/0200-0299/0258.Add Digits/Solution.rs b/solution/0200-0299/0258.Add Digits/Solution.rs index 5f180f1bd5c94..90705d1c7d321 100644 --- a/solution/0200-0299/0258.Add Digits/Solution.rs +++ b/solution/0200-0299/0258.Add Digits/Solution.rs @@ -4,11 +4,10 @@ impl Solution { return num; } Self::add_digits( - num - .to_string() + num.to_string() .chars() .map(|c| c.to_string().parse::().unwrap()) - .sum::() + .sum::(), ) } } diff --git a/solution/0200-0299/0274.H-Index/Solution.rs b/solution/0200-0299/0274.H-Index/Solution.rs index 163d8639a09e9..d33c80aee43f0 100644 --- a/solution/0200-0299/0274.H-Index/Solution.rs +++ b/solution/0200-0299/0274.H-Index/Solution.rs @@ -2,7 +2,7 @@ impl Solution { #[allow(dead_code)] pub fn h_index(citations: Vec) -> i32 { let mut citations = citations; - citations.sort_by(|&lhs, &rhs| { rhs.cmp(&lhs) }); + citations.sort_by(|&lhs, &rhs| rhs.cmp(&lhs)); let n = citations.len(); diff --git a/solution/0200-0299/0287.Find the Duplicate Number/Solution.rs b/solution/0200-0299/0287.Find the Duplicate Number/Solution.rs index 8e65044e108e5..9f2bbfe3047b7 100644 --- a/solution/0200-0299/0287.Find the Duplicate Number/Solution.rs +++ b/solution/0200-0299/0287.Find the Duplicate Number/Solution.rs @@ -6,10 +6,7 @@ impl Solution { while left < right { let mid = (left + right) >> 1; - let cnt = nums - .iter() - .filter(|x| **x <= (mid as i32)) - .count(); + let cnt = nums.iter().filter(|x| **x <= (mid as i32)).count(); if cnt > mid { right = mid; } else { diff --git a/solution/0200-0299/0295.Find Median from Data Stream/README.md b/solution/0200-0299/0295.Find Median from Data Stream/README.md index bc5968be0dbf6..6d493c1a05408 100644 --- a/solution/0200-0299/0295.Find Median from Data Stream/README.md +++ b/solution/0200-0299/0295.Find Median from Data Stream/README.md @@ -317,12 +317,7 @@ impl MedianFinder { } f64::from(self.nums[n >> 1] + self.nums[(n >> 1) - 1]) / 2.0 } -}/** - * Your MedianFinder object will be instantiated and called as such: - * let obj = MedianFinder::new(); - * obj.add_num(num); - * let ret_2: f64 = obj.find_median(); - */ +} ``` #### JavaScript diff --git a/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md b/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md index fb466d3f535c4..90732ca922234 100644 --- a/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md +++ b/solution/0200-0299/0295.Find Median from Data Stream/README_EN.md @@ -312,12 +312,7 @@ impl MedianFinder { } f64::from(self.nums[n >> 1] + self.nums[(n >> 1) - 1]) / 2.0 } -}/** - * Your MedianFinder object will be instantiated and called as such: - * let obj = MedianFinder::new(); - * obj.add_num(num); - * let ret_2: f64 = obj.find_median(); - */ +} ``` #### JavaScript diff --git a/solution/0200-0299/0295.Find Median from Data Stream/Solution.rs b/solution/0200-0299/0295.Find Median from Data Stream/Solution.rs index be3a7ac65744b..52b8117baf98c 100644 --- a/solution/0200-0299/0295.Find Median from Data Stream/Solution.rs +++ b/solution/0200-0299/0295.Find Median from Data Stream/Solution.rs @@ -33,9 +33,4 @@ impl MedianFinder { } f64::from(self.nums[n >> 1] + self.nums[(n >> 1) - 1]) / 2.0 } -}/** - * Your MedianFinder object will be instantiated and called as such: - * let obj = MedianFinder::new(); - * obj.add_num(num); - * let ret_2: f64 = obj.find_median(); - */ +} diff --git a/solution/0200-0299/0296.Best Meeting Point/Solution.rs b/solution/0200-0299/0296.Best Meeting Point/Solution.rs index 4b91ebdb6ec70..38dd14be4b567 100644 --- a/solution/0200-0299/0296.Best Meeting Point/Solution.rs +++ b/solution/0200-0299/0296.Best Meeting Point/Solution.rs @@ -20,8 +20,8 @@ impl Solution { // Since the row vector is originally sorted, we only need to sort the col vector here col_vec.sort(); - Self::compute_manhattan_dis(&row_vec, row_vec[row_vec.len() / 2]) + - Self::compute_manhattan_dis(&col_vec, col_vec[col_vec.len() / 2]) + Self::compute_manhattan_dis(&row_vec, row_vec[row_vec.len() / 2]) + + Self::compute_manhattan_dis(&col_vec, col_vec[col_vec.len() / 2]) } #[allow(dead_code)] diff --git a/solution/0300-0399/0303.Range Sum Query - Immutable/README.md b/solution/0300-0399/0303.Range Sum Query - Immutable/README.md index 7b6a1591a8a99..146166fc8c78a 100644 --- a/solution/0300-0399/0303.Range Sum Query - Immutable/README.md +++ b/solution/0300-0399/0303.Range Sum Query - Immutable/README.md @@ -221,11 +221,7 @@ impl NumArray { fn sum_range(&self, left: i32, right: i32) -> i32 { self.s[(right + 1) as usize] - self.s[left as usize] } -}/** - * Your NumArray object will be instantiated and called as such: - * let obj = NumArray::new(nums); - * let ret_1: i32 = obj.sum_range(left, right); - */ +} ``` #### JavaScript diff --git a/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md b/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md index ebec301258068..07a5c910f3c61 100644 --- a/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md +++ b/solution/0300-0399/0303.Range Sum Query - Immutable/README_EN.md @@ -219,11 +219,7 @@ impl NumArray { fn sum_range(&self, left: i32, right: i32) -> i32 { self.s[(right + 1) as usize] - self.s[left as usize] } -}/** - * Your NumArray object will be instantiated and called as such: - * let obj = NumArray::new(nums); - * let ret_1: i32 = obj.sum_range(left, right); - */ +} ``` #### JavaScript diff --git a/solution/0300-0399/0303.Range Sum Query - Immutable/Solution.rs b/solution/0300-0399/0303.Range Sum Query - Immutable/Solution.rs index aedebce9f9640..c3512ec37f451 100644 --- a/solution/0300-0399/0303.Range Sum Query - Immutable/Solution.rs +++ b/solution/0300-0399/0303.Range Sum Query - Immutable/Solution.rs @@ -19,8 +19,4 @@ impl NumArray { fn sum_range(&self, left: i32, right: i32) -> i32 { self.s[(right + 1) as usize] - self.s[left as usize] } -}/** - * Your NumArray object will be instantiated and called as such: - * let obj = NumArray::new(nums); - * let ret_1: i32 = obj.sum_range(left, right); - */ +} diff --git a/solution/0300-0399/0304.Range Sum Query 2D - Immutable/Solution.rs b/solution/0300-0399/0304.Range Sum Query 2D - Immutable/Solution.rs index 7025b7611f24d..9f0a3e86ce51b 100644 --- a/solution/0300-0399/0304.Range Sum Query 2D - Immutable/Solution.rs +++ b/solution/0300-0399/0304.Range Sum Query 2D - Immutable/Solution.rs @@ -38,10 +38,10 @@ impl NumMatrix { let row2: usize = row2 as usize; let col2: usize = col2 as usize; // Return the value in O(1) - self.prefix_vec[row2 + 1][col2 + 1] - - self.prefix_vec[row2 + 1][col1] - - self.prefix_vec[row1][col2 + 1] + - self.prefix_vec[row1][col1] + self.prefix_vec[row2 + 1][col2 + 1] + - self.prefix_vec[row2 + 1][col1] + - self.prefix_vec[row1][col2 + 1] + + self.prefix_vec[row1][col1] } fn initialize_prefix_vec(&mut self) { @@ -49,10 +49,8 @@ impl NumMatrix { for i in 0..self.n { for j in 0..self.m { self.prefix_vec[i + 1][j + 1] = - self.prefix_vec[i][j + 1] + - self.prefix_vec[i + 1][j] - - self.prefix_vec[i][j] + - self.ref_vec[i][j]; + self.prefix_vec[i][j + 1] + self.prefix_vec[i + 1][j] - self.prefix_vec[i][j] + + self.ref_vec[i][j]; } } self.is_initialized = true; diff --git a/solution/0300-0399/0341.Flatten Nested List Iterator/README.md b/solution/0300-0399/0341.Flatten Nested List Iterator/README.md index bf48ea54955e6..aa61860ad01c5 100644 --- a/solution/0300-0399/0341.Flatten Nested List Iterator/README.md +++ b/solution/0300-0399/0341.Flatten Nested List Iterator/README.md @@ -435,12 +435,7 @@ impl NestedIterator { fn has_next(&self) -> bool { self.index < self.vals.len() } -}/** - * Your NestedIterator object will be instantiated and called as such: - * let obj = NestedIterator::new(nestedList); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} ``` diff --git a/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md b/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md index 7da1e49366927..6f94b4cc44f6c 100644 --- a/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md +++ b/solution/0300-0399/0341.Flatten Nested List Iterator/README_EN.md @@ -433,12 +433,7 @@ impl NestedIterator { fn has_next(&self) -> bool { self.index < self.vals.len() } -}/** - * Your NestedIterator object will be instantiated and called as such: - * let obj = NestedIterator::new(nestedList); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} ``` diff --git a/solution/0300-0399/0341.Flatten Nested List Iterator/Solution.rs b/solution/0300-0399/0341.Flatten Nested List Iterator/Solution.rs index f1d127cbb7045..abf739460a20e 100644 --- a/solution/0300-0399/0341.Flatten Nested List Iterator/Solution.rs +++ b/solution/0300-0399/0341.Flatten Nested List Iterator/Solution.rs @@ -25,10 +25,7 @@ impl NestedIterator { fn new(nestedList: Vec) -> Self { let mut vals = vec![]; Self::dfs(&nestedList, &mut vals); - Self { - vals, - index: 0, - } + Self { vals, index: 0 } } fn next(&mut self) -> i32 { @@ -40,9 +37,4 @@ impl NestedIterator { fn has_next(&self) -> bool { self.index < self.vals.len() } -}/** - * Your NestedIterator object will be instantiated and called as such: - * let obj = NestedIterator::new(nestedList); - * let ret_1: i32 = obj.next(); - * let ret_2: bool = obj.has_next(); - */ +} diff --git a/solution/0300-0399/0362.Design Hit Counter/README.md b/solution/0300-0399/0362.Design Hit Counter/README.md index 83ab02a39a0df..171c9954bf2f1 100644 --- a/solution/0300-0399/0362.Design Hit Counter/README.md +++ b/solution/0300-0399/0362.Design Hit Counter/README.md @@ -273,12 +273,7 @@ impl HitCounter { } l } -}/** - * Your HitCounter object will be instantiated and called as such: - * let obj = HitCounter::new(); - * obj.hit(timestamp); - * let ret_2: i32 = obj.get_hits(timestamp); - */ +} ``` diff --git a/solution/0300-0399/0362.Design Hit Counter/README_EN.md b/solution/0300-0399/0362.Design Hit Counter/README_EN.md index 987e051c7c581..7d87c91c48ebd 100644 --- a/solution/0300-0399/0362.Design Hit Counter/README_EN.md +++ b/solution/0300-0399/0362.Design Hit Counter/README_EN.md @@ -270,12 +270,7 @@ impl HitCounter { } l } -}/** - * Your HitCounter object will be instantiated and called as such: - * let obj = HitCounter::new(); - * obj.hit(timestamp); - * let ret_2: i32 = obj.get_hits(timestamp); - */ +} ``` diff --git a/solution/0300-0399/0362.Design Hit Counter/Solution.rs b/solution/0300-0399/0362.Design Hit Counter/Solution.rs index 025244f80ab6a..20d1ce0842b7d 100644 --- a/solution/0300-0399/0362.Design Hit Counter/Solution.rs +++ b/solution/0300-0399/0362.Design Hit Counter/Solution.rs @@ -32,9 +32,4 @@ impl HitCounter { } l } -}/** - * Your HitCounter object will be instantiated and called as such: - * let obj = HitCounter::new(); - * obj.hit(timestamp); - * let ret_2: i32 = obj.get_hits(timestamp); - */ +} diff --git a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README.md b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README.md index 621d6f7163aaa..ffca29e3979d4 100644 --- a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README.md +++ b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README.md @@ -339,13 +339,7 @@ impl RandomizedSet { let i = rand::thread_rng().gen_range(0, self.list.len()); *self.list.iter().collect::>()[i] } -}/** - * Your RandomizedSet object will be instantiated and called as such: - * let obj = RandomizedSet::new(); - * let ret_1: bool = obj.insert(val); - * let ret_2: bool = obj.remove(val); - * let ret_3: i32 = obj.get_random(); - */ +} ``` #### C# diff --git a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md index 2cb88f5a3acc7..6a530aaffbbc2 100644 --- a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md +++ b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/README_EN.md @@ -333,13 +333,7 @@ impl RandomizedSet { let i = rand::thread_rng().gen_range(0, self.list.len()); *self.list.iter().collect::>()[i] } -}/** - * Your RandomizedSet object will be instantiated and called as such: - * let obj = RandomizedSet::new(); - * let ret_1: bool = obj.insert(val); - * let ret_2: bool = obj.remove(val); - * let ret_3: i32 = obj.get_random(); - */ +} ``` #### C# diff --git a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/Solution.rs b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/Solution.rs index 284c2eb930dc5..5dc5f1d625d5b 100644 --- a/solution/0300-0399/0380.Insert Delete GetRandom O(1)/Solution.rs +++ b/solution/0300-0399/0380.Insert Delete GetRandom O(1)/Solution.rs @@ -1,5 +1,5 @@ -use std::collections::HashSet; use rand::Rng; +use std::collections::HashSet; struct RandomizedSet { list: HashSet, @@ -28,10 +28,4 @@ impl RandomizedSet { let i = rand::thread_rng().gen_range(0, self.list.len()); *self.list.iter().collect::>()[i] } -}/** - * Your RandomizedSet object will be instantiated and called as such: - * let obj = RandomizedSet::new(); - * let ret_1: bool = obj.insert(val); - * let ret_2: bool = obj.remove(val); - * let ret_3: i32 = obj.get_random(); - */ +} diff --git a/solution/0300-0399/0384.Shuffle an Array/README.md b/solution/0300-0399/0384.Shuffle an Array/README.md index c5561d3663bb4..6781a689ac116 100644 --- a/solution/0300-0399/0384.Shuffle an Array/README.md +++ b/solution/0300-0399/0384.Shuffle an Array/README.md @@ -265,12 +265,7 @@ impl Solution { } res } -}/** - * Your Solution object will be instantiated and called as such: - * let obj = Solution::new(nums); - * let ret_1: Vec = obj.reset(); - * let ret_2: Vec = obj.shuffle(); - */ +} ``` #### JavaScript diff --git a/solution/0300-0399/0384.Shuffle an Array/README_EN.md b/solution/0300-0399/0384.Shuffle an Array/README_EN.md index 52d74efef5ffb..b341bcaa9b386 100644 --- a/solution/0300-0399/0384.Shuffle an Array/README_EN.md +++ b/solution/0300-0399/0384.Shuffle an Array/README_EN.md @@ -266,12 +266,7 @@ impl Solution { } res } -}/** - * Your Solution object will be instantiated and called as such: - * let obj = Solution::new(nums); - * let ret_1: Vec = obj.reset(); - * let ret_2: Vec = obj.shuffle(); - */ +} ``` #### JavaScript diff --git a/solution/0300-0399/0384.Shuffle an Array/Solution.rs b/solution/0300-0399/0384.Shuffle an Array/Solution.rs index 8863252b70ee4..2cc42cb9a2965 100644 --- a/solution/0300-0399/0384.Shuffle an Array/Solution.rs +++ b/solution/0300-0399/0384.Shuffle an Array/Solution.rs @@ -25,9 +25,4 @@ impl Solution { } res } -}/** - * Your Solution object will be instantiated and called as such: - * let obj = Solution::new(nums); - * let ret_1: Vec = obj.reset(); - * let ret_2: Vec = obj.shuffle(); - */ +} diff --git a/solution/0300-0399/0389.Find the Difference/Solution.rs b/solution/0300-0399/0389.Find the Difference/Solution.rs index 37fb6da5f3df8..353a8abcd1502 100644 --- a/solution/0300-0399/0389.Find the Difference/Solution.rs +++ b/solution/0300-0399/0389.Find the Difference/Solution.rs @@ -9,14 +9,6 @@ impl Solution { count[(t[i] - b'a') as usize] -= 1; } count[(t[n] - b'a') as usize] -= 1; - char::from( - b'a' + - ( - count - .iter() - .position(|&v| v != 0) - .unwrap() as u8 - ) - ) + char::from(b'a' + (count.iter().position(|&v| v != 0).unwrap() as u8)) } } diff --git a/solution/0300-0399/0396.Rotate Function/Solution.rs b/solution/0300-0399/0396.Rotate Function/Solution.rs index 6af8b42ed80d7..b84b1595d17d0 100644 --- a/solution/0300-0399/0396.Rotate Function/Solution.rs +++ b/solution/0300-0399/0396.Rotate Function/Solution.rs @@ -2,11 +2,7 @@ impl Solution { pub fn max_rotate_function(nums: Vec) -> i32 { let n = nums.len(); let sum: i32 = nums.iter().sum(); - let mut pre: i32 = nums - .iter() - .enumerate() - .map(|(i, &v)| (i as i32) * v) - .sum(); + let mut pre: i32 = nums.iter().enumerate().map(|(i, &v)| (i as i32) * v).sum(); (0..n) .map(|i| { let res = pre; diff --git a/solution/0300-0399/0399.Evaluate Division/Solution.rs b/solution/0300-0399/0399.Evaluate Division/Solution.rs index ade43ec495f66..eeda0f357f3f5 100644 --- a/solution/0300-0399/0399.Evaluate Division/Solution.rs +++ b/solution/0300-0399/0399.Evaluate Division/Solution.rs @@ -15,10 +15,13 @@ impl DisjointSetUnion { let mut nodes = HashMap::new(); for equation in equations.iter() { for iter in equation.iter() { - nodes.insert(iter.clone(), DSUNode { - parent: iter.clone(), - weight: 1.0, - }); + nodes.insert( + iter.clone(), + DSUNode { + parent: iter.clone(), + weight: 1.0, + }, + ); } } DisjointSetUnion { nodes } @@ -66,7 +69,7 @@ impl Solution { pub fn calc_equation( equations: Vec>, values: Vec, - queries: Vec> + queries: Vec>, ) -> Vec { let mut dsu = DisjointSetUnion::new(&equations); for (i, &v) in values.iter().enumerate() { diff --git a/solution/0400-0499/0403.Frog Jump/Solution.rs b/solution/0400-0499/0403.Frog Jump/Solution.rs index 70c33b696963e..e0a8e5657ff7e 100644 --- a/solution/0400-0499/0403.Frog Jump/Solution.rs +++ b/solution/0400-0499/0403.Frog Jump/Solution.rs @@ -20,7 +20,7 @@ impl Solution { k: usize, n: usize, pos: &HashMap, - stones: &Vec + stones: &Vec, ) -> bool { if i == n - 1 { return true; @@ -32,10 +32,9 @@ impl Solution { let k = k as i32; for j in k - 1..=k + 1 { - if - j > 0 && - pos.contains_key(&(stones[i] + j)) && - Self::dfs(record, pos[&(stones[i] + j)], j as usize, n, pos, stones) + if j > 0 + && pos.contains_key(&(stones[i] + j)) + && Self::dfs(record, pos[&(stones[i] + j)], j as usize, n, pos, stones) { record[i][k as usize] = 1; return true; diff --git a/solution/0400-0499/0404.Sum of Left Leaves/Solution.rs b/solution/0400-0499/0404.Sum of Left Leaves/Solution.rs index 3b000521a7e04..2e168eb5fbc1e 100644 --- a/solution/0400-0499/0404.Sum of Left Leaves/Solution.rs +++ b/solution/0400-0499/0404.Sum of Left Leaves/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, is_left: bool) -> i32 { if root.is_none() { diff --git a/solution/0400-0499/0433.Minimum Genetic Mutation/Solution.rs b/solution/0400-0499/0433.Minimum Genetic Mutation/Solution.rs index 0bdd60825252f..95b17161e979e 100644 --- a/solution/0400-0499/0433.Minimum Genetic Mutation/Solution.rs +++ b/solution/0400-0499/0433.Minimum Genetic Mutation/Solution.rs @@ -1,4 +1,4 @@ -use std::collections::{ HashSet, VecDeque }; +use std::collections::{HashSet, VecDeque}; impl Solution { pub fn min_mutation(start_gene: String, end_gene: String, bank: Vec) -> i32 { diff --git a/solution/0400-0499/0445.Add Two Numbers II/Solution.rs b/solution/0400-0499/0445.Add Two Numbers II/Solution.rs index d9f94f76b6aaa..4c2ed9b561d0c 100644 --- a/solution/0400-0499/0445.Add Two Numbers II/Solution.rs +++ b/solution/0400-0499/0445.Add Two Numbers II/Solution.rs @@ -28,7 +28,7 @@ impl Solution { pub fn add_two_numbers( mut l1: Option>, - mut l2: Option> + mut l2: Option>, ) -> Option> { l1 = Self::reverse(l1); l2 = Self::reverse(l2); diff --git a/solution/0400-0499/0445.Add Two Numbers II/Solution2.rs b/solution/0400-0499/0445.Add Two Numbers II/Solution2.rs index 836b4f22bd12a..d602a83128dd0 100644 --- a/solution/0400-0499/0445.Add Two Numbers II/Solution2.rs +++ b/solution/0400-0499/0445.Add Two Numbers II/Solution2.rs @@ -26,7 +26,7 @@ impl Solution { pub fn add_two_numbers( l1: Option>, - l2: Option> + l2: Option>, ) -> Option> { let mut s1 = Self::create_stack(l1); let mut s2 = Self::create_stack(l2); @@ -40,12 +40,10 @@ impl Solution { if let Some(val) = s2.pop() { carry += val; } - dummy.next = Some( - Box::new(ListNode { - val: carry % 10, - next: dummy.next.take(), - }) - ); + dummy.next = Some(Box::new(ListNode { + val: carry % 10, + next: dummy.next.take(), + })); carry /= 10; } dummy.next.take() diff --git a/solution/0400-0499/0450.Delete Node in a BST/Solution.rs b/solution/0400-0499/0450.Delete Node in a BST/Solution.rs index f745a01e504c1..8e51840c67262 100644 --- a/solution/0400-0499/0450.Delete Node in a BST/Solution.rs +++ b/solution/0400-0499/0450.Delete Node in a BST/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>) -> i32 { let node = root.as_ref().unwrap().borrow(); @@ -29,7 +29,7 @@ impl Solution { pub fn delete_node( mut root: Option>>, - key: i32 + key: i32, ) -> Option>> { if root.is_some() { let mut node = root.as_mut().unwrap().borrow_mut(); diff --git a/solution/0400-0499/0454.4Sum II/Solution.rs b/solution/0400-0499/0454.4Sum II/Solution.rs index d5cb1dd0b015c..b9f0349f906eb 100644 --- a/solution/0400-0499/0454.4Sum II/Solution.rs +++ b/solution/0400-0499/0454.4Sum II/Solution.rs @@ -5,7 +5,7 @@ impl Solution { nums1: Vec, nums2: Vec, nums3: Vec, - nums4: Vec + nums4: Vec, ) -> i32 { let mut cnt = HashMap::new(); for &a in &nums1 { diff --git a/solution/0400-0499/0460.LFU Cache/README.md b/solution/0400-0499/0460.LFU Cache/README.md index 5045318b4b8ea..ea4ea869837e1 100644 --- a/solution/0400-0499/0460.LFU Cache/README.md +++ b/solution/0400-0499/0460.LFU Cache/README.md @@ -755,12 +755,7 @@ impl LFUCache { } }; } -}/** - * Your LFUCache object will be instantiated and called as such: - * let obj = LFUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} ``` diff --git a/solution/0400-0499/0460.LFU Cache/README_EN.md b/solution/0400-0499/0460.LFU Cache/README_EN.md index 5b397a8c2442d..352a094b58c42 100644 --- a/solution/0400-0499/0460.LFU Cache/README_EN.md +++ b/solution/0400-0499/0460.LFU Cache/README_EN.md @@ -736,12 +736,7 @@ impl LFUCache { } }; } -}/** - * Your LFUCache object will be instantiated and called as such: - * let obj = LFUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} ``` diff --git a/solution/0400-0499/0460.LFU Cache/Solution.rs b/solution/0400-0499/0460.LFU Cache/Solution.rs index e3b2f8f44dfb0..60d7b58a14f8d 100644 --- a/solution/0400-0499/0460.LFU Cache/Solution.rs +++ b/solution/0400-0499/0460.LFU Cache/Solution.rs @@ -176,9 +176,4 @@ impl LFUCache { } }; } -}/** - * Your LFUCache object will be instantiated and called as such: - * let obj = LFUCache::new(capacity); - * let ret_1: i32 = obj.get(key); - * obj.put(key, value); - */ +} diff --git a/solution/0400-0499/0481.Magical String/Solution.rs b/solution/0400-0499/0481.Magical String/Solution.rs index b728e4f643050..e9b0b628cb9c5 100644 --- a/solution/0400-0499/0481.Magical String/Solution.rs +++ b/solution/0400-0499/0481.Magical String/Solution.rs @@ -11,10 +11,6 @@ impl Solution { } i += 1; } - s - .as_bytes() - [0..n].iter() - .filter(|&v| v == &b'1') - .count() as i32 + s.as_bytes()[0..n].iter().filter(|&v| v == &b'1').count() as i32 } } diff --git a/solution/0400-0499/0486.Predict the Winner/Solution.rs b/solution/0400-0499/0486.Predict the Winner/Solution.rs index f82e1e740ebd9..b6ad1ea47965a 100644 --- a/solution/0400-0499/0486.Predict the Winner/Solution.rs +++ b/solution/0400-0499/0486.Predict the Winner/Solution.rs @@ -16,7 +16,7 @@ impl Solution { // Take i-th num nums[i] - dp[i + 1][j], // Take j-th num - nums[j] - dp[i][j - 1] + nums[j] - dp[i][j - 1], ); } } diff --git a/solution/0500-0599/0508.Most Frequent Subtree Sum/Solution.rs b/solution/0500-0599/0508.Most Frequent Subtree Sum/Solution.rs index 9c4b85e9332e4..843be9696200d 100644 --- a/solution/0500-0599/0508.Most Frequent Subtree Sum/Solution.rs +++ b/solution/0500-0599/0508.Most Frequent Subtree Sum/Solution.rs @@ -16,14 +16,14 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; impl Solution { fn dfs( root: &Option>>, map: &mut HashMap, - max: &mut i32 + max: &mut i32, ) -> i32 { if root.is_none() { return 0; diff --git a/solution/0500-0599/0513.Find Bottom Left Tree Value/Solution.rs b/solution/0500-0599/0513.Find Bottom Left Tree Value/Solution.rs index cf76c64fd027e..1279fe72ba73d 100644 --- a/solution/0500-0599/0513.Find Bottom Left Tree Value/Solution.rs +++ b/solution/0500-0599/0513.Find Bottom Left Tree Value/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn find_bottom_left_value(root: Option>>) -> i32 { let mut queue = VecDeque::new(); diff --git a/solution/0500-0599/0513.Find Bottom Left Tree Value/Solution2.rs b/solution/0500-0599/0513.Find Bottom Left Tree Value/Solution2.rs index cb06fc1b9d789..9d782fcd5c64f 100644 --- a/solution/0500-0599/0513.Find Bottom Left Tree Value/Solution2.rs +++ b/solution/0500-0599/0513.Find Bottom Left Tree Value/Solution2.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, cur: i32, max: &mut i32, res: &mut i32) { if root.is_none() { diff --git a/solution/0500-0599/0515.Find Largest Value in Each Tree Row/Solution.rs b/solution/0500-0599/0515.Find Largest Value in Each Tree Row/Solution.rs index ca490298c56a3..7f342dfbf69fb 100644 --- a/solution/0500-0599/0515.Find Largest Value in Each Tree Row/Solution.rs +++ b/solution/0500-0599/0515.Find Largest Value in Each Tree Row/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn largest_values(root: Option>>) -> Vec { let mut res = Vec::new(); diff --git a/solution/0500-0599/0515.Find Largest Value in Each Tree Row/Solution2.rs b/solution/0500-0599/0515.Find Largest Value in Each Tree Row/Solution2.rs index 436c3c40c218f..01840703d12d9 100644 --- a/solution/0500-0599/0515.Find Largest Value in Each Tree Row/Solution2.rs +++ b/solution/0500-0599/0515.Find Largest Value in Each Tree Row/Solution2.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, depth: usize, res: &mut Vec) { if root.is_none() { diff --git a/solution/0500-0599/0528.Random Pick with Weight/README.md b/solution/0500-0599/0528.Random Pick with Weight/README.md index 35c34f90782aa..6648e51e316aa 100644 --- a/solution/0500-0599/0528.Random Pick with Weight/README.md +++ b/solution/0500-0599/0528.Random Pick with Weight/README.md @@ -263,11 +263,7 @@ impl Solution { } (left - 1) as i32 } -}/** - * Your Solution object will be instantiated and called as such: - * let obj = Solution::new(w); - * let ret_1: i32 = obj.pick_index(); - */ +} ``` #### JavaScript diff --git a/solution/0500-0599/0528.Random Pick with Weight/README_EN.md b/solution/0500-0599/0528.Random Pick with Weight/README_EN.md index 6187ce9867120..b4df0a1599934 100644 --- a/solution/0500-0599/0528.Random Pick with Weight/README_EN.md +++ b/solution/0500-0599/0528.Random Pick with Weight/README_EN.md @@ -262,11 +262,7 @@ impl Solution { } (left - 1) as i32 } -}/** - * Your Solution object will be instantiated and called as such: - * let obj = Solution::new(w); - * let ret_1: i32 = obj.pick_index(); - */ +} ``` #### JavaScript diff --git a/solution/0500-0599/0528.Random Pick with Weight/Solution.rs b/solution/0500-0599/0528.Random Pick with Weight/Solution.rs index 5a6dcfa641990..7469ebba28c27 100644 --- a/solution/0500-0599/0528.Random Pick with Weight/Solution.rs +++ b/solution/0500-0599/0528.Random Pick with Weight/Solution.rs @@ -1,4 +1,4 @@ -use rand::{ thread_rng, Rng }; +use rand::{thread_rng, Rng}; struct Solution { sum: Vec, @@ -31,8 +31,4 @@ impl Solution { } (left - 1) as i32 } -}/** - * Your Solution object will be instantiated and called as such: - * let obj = Solution::new(w); - * let ret_1: i32 = obj.pick_index(); - */ +} diff --git a/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.rs b/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.rs index 7b551f40c79ab..cf5396d9060ed 100644 --- a/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.rs +++ b/solution/0500-0599/0530.Minimum Absolute Difference in BST/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { #[allow(dead_code)] pub fn get_minimum_difference(root: Option>>) -> i32 { diff --git a/solution/0500-0599/0542.01 Matrix/Solution.rs b/solution/0500-0599/0542.01 Matrix/Solution.rs index 1c90d9882f87a..4f6b1f7f38793 100644 --- a/solution/0500-0599/0542.01 Matrix/Solution.rs +++ b/solution/0500-0599/0542.01 Matrix/Solution.rs @@ -28,9 +28,8 @@ impl Solution { for pair in &traverse_vec { let cur_x = pair.0 + (x as i32); let cur_y = pair.1 + (y as i32); - if - Solution::check_bounds(cur_x, cur_y, n as i32, m as i32) && - ret_vec[cur_x as usize][cur_y as usize] == -1 + if Solution::check_bounds(cur_x, cur_y, n as i32, m as i32) + && ret_vec[cur_x as usize][cur_y as usize] == -1 { // The current cell has not be updated yet, and is also in bound ret_vec[cur_x as usize][cur_y as usize] = ret_vec[x][y] + 1; diff --git a/solution/0500-0599/0543.Diameter of Binary Tree/Solution.rs b/solution/0500-0599/0543.Diameter of Binary Tree/Solution.rs index 12da90f6d12ab..3d336dc2bc21a 100644 --- a/solution/0500-0599/0543.Diameter of Binary Tree/Solution.rs +++ b/solution/0500-0599/0543.Diameter of Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, res: &mut i32) -> i32 { if root.is_none() { diff --git a/solution/0500-0599/0572.Subtree of Another Tree/Solution.rs b/solution/0500-0599/0572.Subtree of Another Tree/Solution.rs index 60b1ea1c5b8dd..07f98f618515f 100644 --- a/solution/0500-0599/0572.Subtree of Another Tree/Solution.rs +++ b/solution/0500-0599/0572.Subtree of Another Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, sub_root: &Option>>) -> bool { if root.is_none() && sub_root.is_none() { @@ -28,26 +28,26 @@ impl Solution { } let root = root.as_ref().unwrap().borrow(); let sub_root = sub_root.as_ref().unwrap().borrow(); - root.val == sub_root.val && - Self::dfs(&root.left, &sub_root.left) && - Self::dfs(&root.right, &sub_root.right) + root.val == sub_root.val + && Self::dfs(&root.left, &sub_root.left) + && Self::dfs(&root.right, &sub_root.right) } fn help( root: &Option>>, - sub_root: &Option>> + sub_root: &Option>>, ) -> bool { if root.is_none() { return false; } - Self::dfs(root, sub_root) || - Self::help(&root.as_ref().unwrap().borrow().left, sub_root) || - Self::help(&root.as_ref().unwrap().borrow().right, sub_root) + Self::dfs(root, sub_root) + || Self::help(&root.as_ref().unwrap().borrow().left, sub_root) + || Self::help(&root.as_ref().unwrap().borrow().right, sub_root) } pub fn is_subtree( root: Option>>, - sub_root: Option>> + sub_root: Option>>, ) -> bool { Self::help(&root, &sub_root) } diff --git a/solution/0500-0599/0591.Tag Validator/Solution.rs b/solution/0500-0599/0591.Tag Validator/Solution.rs index 68b6e48525bb5..ff41c876fa60c 100644 --- a/solution/0500-0599/0591.Tag Validator/Solution.rs +++ b/solution/0500-0599/0591.Tag Validator/Solution.rs @@ -2,12 +2,7 @@ impl Solution { pub fn is_valid(code: String) -> bool { fn check(tag: &str) -> bool { let n = tag.len(); - n >= 1 && - n <= 9 && - tag - .as_bytes() - .iter() - .all(|b| b.is_ascii_uppercase()) + n >= 1 && n <= 9 && tag.as_bytes().iter().all(|b| b.is_ascii_uppercase()) } let mut stk = Vec::new(); diff --git a/solution/0500-0599/0599.Minimum Index Sum of Two Lists/Solution.rs b/solution/0500-0599/0599.Minimum Index Sum of Two Lists/Solution.rs index 334be333aefaf..877219d1c36bc 100644 --- a/solution/0500-0599/0599.Minimum Index Sum of Two Lists/Solution.rs +++ b/solution/0500-0599/0599.Minimum Index Sum of Two Lists/Solution.rs @@ -6,21 +6,18 @@ impl Solution { let map: HashMap = HashMap::from_iter(list1.into_iter().zip(0..)); let mut res = vec![]; let mut min_i = usize::MAX; - list2 - .into_iter() - .enumerate() - .for_each(|(i, key)| { - if map.contains_key(&key) { - let sum_i = map.get(&key).unwrap() + i; - if sum_i <= min_i { - if sum_i < min_i { - min_i = sum_i; - res.clear(); - } - res.push(key); + list2.into_iter().enumerate().for_each(|(i, key)| { + if map.contains_key(&key) { + let sum_i = map.get(&key).unwrap() + i; + if sum_i <= min_i { + if sum_i < min_i { + min_i = sum_i; + res.clear(); } + res.push(key); } - }); + } + }); res } } diff --git a/solution/0600-0699/0617.Merge Two Binary Trees/Solution.rs b/solution/0600-0699/0617.Merge Two Binary Trees/Solution.rs index 3e9db476b91d6..d8dee1388c283 100644 --- a/solution/0600-0699/0617.Merge Two Binary Trees/Solution.rs +++ b/solution/0600-0699/0617.Merge Two Binary Trees/Solution.rs @@ -16,12 +16,12 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn merge_trees( root1: Option>>, - root2: Option>> + root2: Option>>, ) -> Option>> { match (root1.is_some(), root2.is_some()) { (false, false) => None, diff --git a/solution/0600-0699/0622.Design Circular Queue/README.md b/solution/0600-0699/0622.Design Circular Queue/README.md index 145098c1cca8f..fae9aaced7aca 100644 --- a/solution/0600-0699/0622.Design Circular Queue/README.md +++ b/solution/0600-0699/0622.Design Circular Queue/README.md @@ -454,16 +454,7 @@ impl MyCircularQueue { fn is_full(&self) -> bool { self.right - self.left == self.capacity } -}/** - * Your MyCircularQueue object will be instantiated and called as such: - * let obj = MyCircularQueue::new(k); - * let ret_1: bool = obj.en_queue(value); - * let ret_2: bool = obj.de_queue(); - * let ret_3: i32 = obj.front(); - * let ret_4: i32 = obj.rear(); - * let ret_5: bool = obj.is_empty(); - * let ret_6: bool = obj.is_full(); - */ +} ``` diff --git a/solution/0600-0699/0622.Design Circular Queue/README_EN.md b/solution/0600-0699/0622.Design Circular Queue/README_EN.md index 6bd85a9a93241..74443b85a2463 100644 --- a/solution/0600-0699/0622.Design Circular Queue/README_EN.md +++ b/solution/0600-0699/0622.Design Circular Queue/README_EN.md @@ -463,16 +463,7 @@ impl MyCircularQueue { fn is_full(&self) -> bool { self.right - self.left == self.capacity } -}/** - * Your MyCircularQueue object will be instantiated and called as such: - * let obj = MyCircularQueue::new(k); - * let ret_1: bool = obj.en_queue(value); - * let ret_2: bool = obj.de_queue(); - * let ret_3: i32 = obj.front(); - * let ret_4: i32 = obj.rear(); - * let ret_5: bool = obj.is_empty(); - * let ret_6: bool = obj.is_full(); - */ +} ``` diff --git a/solution/0600-0699/0622.Design Circular Queue/Solution.rs b/solution/0600-0699/0622.Design Circular Queue/Solution.rs index 1182ee831c768..450fad52c5237 100644 --- a/solution/0600-0699/0622.Design Circular Queue/Solution.rs +++ b/solution/0600-0699/0622.Design Circular Queue/Solution.rs @@ -58,13 +58,4 @@ impl MyCircularQueue { fn is_full(&self) -> bool { self.right - self.left == self.capacity } -}/** - * Your MyCircularQueue object will be instantiated and called as such: - * let obj = MyCircularQueue::new(k); - * let ret_1: bool = obj.en_queue(value); - * let ret_2: bool = obj.de_queue(); - * let ret_3: i32 = obj.front(); - * let ret_4: i32 = obj.rear(); - * let ret_5: bool = obj.is_empty(); - * let ret_6: bool = obj.is_full(); - */ +} diff --git a/solution/0600-0699/0637.Average of Levels in Binary Tree/Solution.rs b/solution/0600-0699/0637.Average of Levels in Binary Tree/Solution.rs index 2d48860f9bcc2..788b9c5eb2edb 100644 --- a/solution/0600-0699/0637.Average of Levels in Binary Tree/Solution.rs +++ b/solution/0600-0699/0637.Average of Levels in Binary Tree/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn average_of_levels(root: Option>>) -> Vec { diff --git a/solution/0600-0699/0645.Set Mismatch/Solution.rs b/solution/0600-0699/0645.Set Mismatch/Solution.rs index 1957412fa9b0c..a22f17d369cff 100644 --- a/solution/0600-0699/0645.Set Mismatch/Solution.rs +++ b/solution/0600-0699/0645.Set Mismatch/Solution.rs @@ -3,7 +3,12 @@ impl Solution { pub fn find_error_nums(nums: Vec) -> Vec { let n = nums.len() as i32; let s1 = ((1 + n) * n) / 2; - let s2 = nums.iter().cloned().collect::>().iter().sum::(); + let s2 = nums + .iter() + .cloned() + .collect::>() + .iter() + .sum::(); let s: i32 = nums.iter().sum(); vec![s - s2, s1 - s2] } diff --git a/solution/0600-0699/0652.Find Duplicate Subtrees/Solution.rs b/solution/0600-0699/0652.Find Duplicate Subtrees/Solution.rs index 40d6976b7e419..8e9a47c6d6d5c 100644 --- a/solution/0600-0699/0652.Find Duplicate Subtrees/Solution.rs +++ b/solution/0600-0699/0652.Find Duplicate Subtrees/Solution.rs @@ -16,14 +16,14 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; impl Solution { fn dfs( root: &Option>>, map: &mut HashMap, - res: &mut Vec>>> + res: &mut Vec>>>, ) -> String { if root.is_none() { return String::from('#'); @@ -46,7 +46,7 @@ impl Solution { } pub fn find_duplicate_subtrees( - root: Option>> + root: Option>>, ) -> Vec>>> { let mut map = HashMap::new(); let mut res = Vec::new(); diff --git a/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.rs b/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.rs index ab16e174a2ddb..297c6e59e38a4 100644 --- a/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.rs +++ b/solution/0600-0699/0653.Two Sum IV - Input is a BST/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; -use std::collections::{ HashSet, VecDeque }; +use std::collections::{HashSet, VecDeque}; +use std::rc::Rc; impl Solution { pub fn find_target(root: Option>>, k: i32) -> bool { let mut set = HashSet::new(); diff --git a/solution/0600-0699/0654.Maximum Binary Tree/Solution.rs b/solution/0600-0699/0654.Maximum Binary Tree/Solution.rs index 512faa57f3e4f..3b2877b34d048 100644 --- a/solution/0600-0699/0654.Maximum Binary Tree/Solution.rs +++ b/solution/0600-0699/0654.Maximum Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn construct(nums: &Vec, start: usize, end: usize) -> Option>> { if start >= end { @@ -31,15 +31,11 @@ impl Solution { max_val = nums[i]; } } - Some( - Rc::new( - RefCell::new(TreeNode { - val: max_val, - left: Self::construct(nums, start, idx), - right: Self::construct(nums, idx + 1, end), - }) - ) - ) + Some(Rc::new(RefCell::new(TreeNode { + val: max_val, + left: Self::construct(nums, start, idx), + right: Self::construct(nums, idx + 1, end), + }))) } pub fn construct_maximum_binary_tree(nums: Vec) -> Option>> { diff --git a/solution/0600-0699/0655.Print Binary Tree/Solution.rs b/solution/0600-0699/0655.Print Binary Tree/Solution.rs index 9b5ef7f11b5fe..4468521eed085 100644 --- a/solution/0600-0699/0655.Print Binary Tree/Solution.rs +++ b/solution/0600-0699/0655.Print Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn get_height(root: &Option>>, h: u32) -> u32 { if let Some(node) = root { @@ -32,15 +32,27 @@ impl Solution { i: usize, j: usize, res: &mut Vec>, - height: u32 + height: u32, ) { if root.is_none() { return; } let node = root.as_ref().unwrap().borrow(); res[i][j] = node.val.to_string(); - Self::dfs(&node.left, i + 1, j - (2usize).pow(height - (i as u32) - 1), res, height); - Self::dfs(&node.right, i + 1, j + (2usize).pow(height - (i as u32) - 1), res, height); + Self::dfs( + &node.left, + i + 1, + j - (2usize).pow(height - (i as u32) - 1), + res, + height, + ); + Self::dfs( + &node.right, + i + 1, + j + (2usize).pow(height - (i as u32) - 1), + res, + height, + ); } pub fn print_tree(root: Option>>) -> Vec> { diff --git a/solution/0600-0699/0669.Trim a Binary Search Tree/Solution.rs b/solution/0600-0699/0669.Trim a Binary Search Tree/Solution.rs index 8f5fa3de377e5..c042dd80402b9 100644 --- a/solution/0600-0699/0669.Trim a Binary Search Tree/Solution.rs +++ b/solution/0600-0699/0669.Trim a Binary Search Tree/Solution.rs @@ -16,13 +16,13 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn trim_bst( mut root: Option>>, low: i32, - high: i32 + high: i32, ) -> Option>> { if root.is_none() { return root; diff --git a/solution/0600-0699/0675.Cut Off Trees for Golf Event/Solution.rs b/solution/0600-0699/0675.Cut Off Trees for Golf Event/Solution.rs index 29c56b572d508..5889c222c6760 100644 --- a/solution/0600-0699/0675.Cut Off Trees for Golf Event/Solution.rs +++ b/solution/0600-0699/0675.Cut Off Trees for Golf Event/Solution.rs @@ -1,12 +1,7 @@ use std::collections::HashSet; use std::collections::VecDeque; -const DIRS: [[i32; 2]; 4] = [ - [-1, 0], - [1, 0], - [0, -1], - [0, 1], -]; +const DIRS: [[i32; 2]; 4] = [[-1, 0], [1, 0], [0, -1], [0, 1]]; impl Solution { pub fn cut_off_tree(forest: Vec>) -> i32 { @@ -29,13 +24,12 @@ impl Solution { let x = state / col + DIRS[k][0]; let y = (state % col) + DIRS[k][1]; let nxt = x * col + y; - if - x >= 0 && - x < row && - y >= 0 && - y < col && - forest[x as usize][y as usize] != 0 && - !vis.contains(&nxt) + if x >= 0 + && x < row + && y >= 0 + && y < col + && forest[x as usize][y as usize] != 0 + && !vis.contains(&nxt) { queue.push_back(nxt); vis.insert(nxt); diff --git a/solution/0600-0699/0676.Implement Magic Dictionary/README.md b/solution/0600-0699/0676.Implement Magic Dictionary/README.md index 8abea45fcbd62..72eca0abaa4c9 100644 --- a/solution/0600-0699/0676.Implement Magic Dictionary/README.md +++ b/solution/0600-0699/0676.Implement Magic Dictionary/README.md @@ -504,12 +504,7 @@ impl MagicDictionary { fn search(&self, search_word: String) -> bool { self.trie.search(&search_word, 0) } -}/** - * Your MagicDictionary object will be instantiated and called as such: - * let obj = MagicDictionary::new(); - * obj.build_dict(dictionary); - * let ret_2: bool = obj.search(searchWord); - */ +} ``` diff --git a/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md b/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md index 46c9eed17813d..ac7f2df4d4980 100644 --- a/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md +++ b/solution/0600-0699/0676.Implement Magic Dictionary/README_EN.md @@ -496,12 +496,7 @@ impl MagicDictionary { fn search(&self, search_word: String) -> bool { self.trie.search(&search_word, 0) } -}/** - * Your MagicDictionary object will be instantiated and called as such: - * let obj = MagicDictionary::new(); - * obj.build_dict(dictionary); - * let ret_2: bool = obj.search(searchWord); - */ +} ``` diff --git a/solution/0600-0699/0676.Implement Magic Dictionary/Solution.rs b/solution/0600-0699/0676.Implement Magic Dictionary/Solution.rs index 25817b12d7611..c8ce751b9f346 100644 --- a/solution/0600-0699/0676.Implement Magic Dictionary/Solution.rs +++ b/solution/0600-0699/0676.Implement Magic Dictionary/Solution.rs @@ -38,12 +38,7 @@ impl Trie { if diff == 0 { for (i, child) in self.children.iter().enumerate() { if i != index && child.is_some() { - if - child - .as_ref() - .unwrap() - .search(&word[1..], 1) - { + if child.as_ref().unwrap().search(&word[1..], 1) { return true; } } @@ -76,9 +71,4 @@ impl MagicDictionary { fn search(&self, search_word: String) -> bool { self.trie.search(&search_word, 0) } -}/** - * Your MagicDictionary object will be instantiated and called as such: - * let obj = MagicDictionary::new(); - * obj.build_dict(dictionary); - * let ret_2: bool = obj.search(searchWord); - */ +} diff --git a/solution/0600-0699/0687.Longest Univalue Path/Solution.rs b/solution/0600-0699/0687.Longest Univalue Path/Solution.rs index c22ef18bed7bb..44615f3b8031d 100644 --- a/solution/0600-0699/0687.Longest Univalue Path/Solution.rs +++ b/solution/0600-0699/0687.Longest Univalue Path/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, target: i32, res: &mut i32) -> i32 { if root.is_none() { @@ -40,7 +40,11 @@ impl Solution { } let mut res = 0; - Self::dfs(&root, root.as_ref().unwrap().as_ref().borrow().val, &mut res); + Self::dfs( + &root, + root.as_ref().unwrap().as_ref().borrow().val, + &mut res, + ); res } } diff --git a/solution/0600-0699/0691.Stickers to Spell Word/Solution.rs b/solution/0600-0699/0691.Stickers to Spell Word/Solution.rs index c743c820b699d..f55fb0563c5d9 100644 --- a/solution/0600-0699/0691.Stickers to Spell Word/Solution.rs +++ b/solution/0600-0699/0691.Stickers to Spell Word/Solution.rs @@ -1,4 +1,4 @@ -use std::collections::{ HashSet, VecDeque }; +use std::collections::{HashSet, VecDeque}; impl Solution { pub fn min_stickers(stickers: Vec, target: String) -> i32 { diff --git a/solution/0700-0799/0707.Design Linked List/README.md b/solution/0700-0799/0707.Design Linked List/README.md index 7afafe73df2d7..1ad3c77559131 100644 --- a/solution/0700-0799/0707.Design Linked List/README.md +++ b/solution/0700-0799/0707.Design Linked List/README.md @@ -540,15 +540,7 @@ impl MyLinkedList { cur.next = cur.next.take().and_then(|n| n.next); self.head = dummy.next; } -}/** - * Your MyLinkedList object will be instantiated and called as such: - * let obj = MyLinkedList::new(); - * let ret_1: i32 = obj.get(index); - * obj.add_at_head(val); - * obj.add_at_tail(val); - * obj.add_at_index(index, val); - * obj.delete_at_index(index); - */ +} ``` diff --git a/solution/0700-0799/0707.Design Linked List/README_EN.md b/solution/0700-0799/0707.Design Linked List/README_EN.md index 5832a2aaa27bf..8d68d1121bdfa 100644 --- a/solution/0700-0799/0707.Design Linked List/README_EN.md +++ b/solution/0700-0799/0707.Design Linked List/README_EN.md @@ -522,15 +522,7 @@ impl MyLinkedList { cur.next = cur.next.take().and_then(|n| n.next); self.head = dummy.next; } -}/** - * Your MyLinkedList object will be instantiated and called as such: - * let obj = MyLinkedList::new(); - * let ret_1: i32 = obj.get(index); - * obj.add_at_head(val); - * obj.add_at_tail(val); - * obj.add_at_index(index, val); - * obj.delete_at_index(index); - */ +} ``` diff --git a/solution/0700-0799/0707.Design Linked List/Solution.rs b/solution/0700-0799/0707.Design Linked List/Solution.rs index c61734e279289..9bbaf2444ea87 100644 --- a/solution/0700-0799/0707.Design Linked List/Solution.rs +++ b/solution/0700-0799/0707.Design Linked List/Solution.rs @@ -32,12 +32,10 @@ impl MyLinkedList { } fn add_at_head(&mut self, val: i32) { - self.head = Some( - Box::new(ListNode { - val, - next: self.head.take(), - }) - ); + self.head = Some(Box::new(ListNode { + val, + next: self.head.take(), + })); } fn add_at_tail(&mut self, val: i32) { @@ -66,12 +64,10 @@ impl MyLinkedList { cur = cur.next.as_mut().unwrap(); index -= 1; } - cur.next = Some( - Box::new(ListNode { - val, - next: cur.next.take(), - }) - ); + cur.next = Some(Box::new(ListNode { + val, + next: cur.next.take(), + })); self.head = dummy.next; } @@ -90,12 +86,4 @@ impl MyLinkedList { cur.next = cur.next.take().and_then(|n| n.next); self.head = dummy.next; } -}/** - * Your MyLinkedList object will be instantiated and called as such: - * let obj = MyLinkedList::new(); - * let ret_1: i32 = obj.get(index); - * obj.add_at_head(val); - * obj.add_at_tail(val); - * obj.add_at_index(index, val); - * obj.delete_at_index(index); - */ +} diff --git a/solution/0700-0799/0713.Subarray Product Less Than K/Solution.rs b/solution/0700-0799/0713.Subarray Product Less Than K/Solution.rs index 652789fa30e70..4514c5f215eee 100644 --- a/solution/0700-0799/0713.Subarray Product Less Than K/Solution.rs +++ b/solution/0700-0799/0713.Subarray Product Less Than K/Solution.rs @@ -7,16 +7,14 @@ impl Solution { let mut res = 0; let mut product = 1; let mut i = 0; - nums.iter() - .enumerate() - .for_each(|(j, v)| { - product *= v; - while product >= k { - product /= nums[i]; - i += 1; - } - res += j - i + 1; - }); + nums.iter().enumerate().for_each(|(j, v)| { + product *= v; + while product >= k { + product /= nums[i]; + i += 1; + } + res += j - i + 1; + }); res as i32 } } diff --git a/solution/0700-0799/0728.Self Dividing Numbers/Solution.rs b/solution/0700-0799/0728.Self Dividing Numbers/Solution.rs index a45b74235777f..6f8d978dc9ecf 100644 --- a/solution/0700-0799/0728.Self Dividing Numbers/Solution.rs +++ b/solution/0700-0799/0728.Self Dividing Numbers/Solution.rs @@ -3,18 +3,16 @@ impl Solution { let mut res = vec![]; for i in left..=right { let mut num = i; - if ( - loop { - if num == 0 { - break true; - } - let j = num % 10; - if j == 0 || i % j != 0 { - break false; - } - num /= 10; + if (loop { + if num == 0 { + break true; } - ) { + let j = num % 10; + if j == 0 || i % j != 0 { + break false; + } + num /= 10; + }) { res.push(i); } } diff --git a/solution/0700-0799/0729.My Calendar I/README.md b/solution/0700-0799/0729.My Calendar I/README.md index 2574e27231301..f825b3610b8fe 100644 --- a/solution/0700-0799/0729.My Calendar I/README.md +++ b/solution/0700-0799/0729.My Calendar I/README.md @@ -253,11 +253,7 @@ impl MyCalendar { self.bt.insert(start, end); true } -}/** - * Your MyCalendar object will be instantiated and called as such: - * let obj = MyCalendar::new(); - * let ret_1: bool = obj.book(start, end); - */ +} ``` diff --git a/solution/0700-0799/0729.My Calendar I/README_EN.md b/solution/0700-0799/0729.My Calendar I/README_EN.md index 1e2fad8bf5672..5f3dce96c5243 100644 --- a/solution/0700-0799/0729.My Calendar I/README_EN.md +++ b/solution/0700-0799/0729.My Calendar I/README_EN.md @@ -251,11 +251,7 @@ impl MyCalendar { self.bt.insert(start, end); true } -}/** - * Your MyCalendar object will be instantiated and called as such: - * let obj = MyCalendar::new(); - * let ret_1: bool = obj.book(start, end); - */ +} ``` diff --git a/solution/0700-0799/0729.My Calendar I/Solution.rs b/solution/0700-0799/0729.My Calendar I/Solution.rs index 8867c57bb1a4c..2c489c868f025 100644 --- a/solution/0700-0799/0729.My Calendar I/Solution.rs +++ b/solution/0700-0799/0729.My Calendar I/Solution.rs @@ -30,8 +30,4 @@ impl MyCalendar { self.bt.insert(start, end); true } -}/** - * Your MyCalendar object will be instantiated and called as such: - * let obj = MyCalendar::new(); - * let ret_1: bool = obj.book(start, end); - */ +} diff --git a/solution/0700-0799/0767.Reorganize String/Solution.rs b/solution/0700-0799/0767.Reorganize String/Solution.rs index cfc639e028ae5..e58d224d8cd64 100644 --- a/solution/0700-0799/0767.Reorganize String/Solution.rs +++ b/solution/0700-0799/0767.Reorganize String/Solution.rs @@ -1,4 +1,4 @@ -use std::collections::{ HashMap, BinaryHeap, VecDeque }; +use std::collections::{BinaryHeap, HashMap, VecDeque}; impl Solution { #[allow(dead_code)] diff --git a/solution/0700-0799/0778.Swim in Rising Water/Solution.rs b/solution/0700-0799/0778.Swim in Rising Water/Solution.rs index ebf2ec7183916..4220d60137d93 100644 --- a/solution/0700-0799/0778.Swim in Rising Water/Solution.rs +++ b/solution/0700-0799/0778.Swim in Rising Water/Solution.rs @@ -1,9 +1,4 @@ -const DIR: [(i32, i32); 4] = [ - (-1, 0), - (1, 0), - (0, -1), - (0, 1), -]; +const DIR: [(i32, i32); 4] = [(-1, 0), (1, 0), (0, -1), (0, 1)]; impl Solution { #[allow(dead_code)] @@ -43,9 +38,8 @@ impl Solution { for (dx, dy) in DIR { let x = dx + (i as i32); let y = dy + (j as i32); - if - Self::check_bounds(x, y, n as i32, m as i32) && - grid[x as usize][y as usize] <= cur_time + if Self::check_bounds(x, y, n as i32, m as i32) + && grid[x as usize][y as usize] <= cur_time { Self::union(i * m + j, (x as usize) * m + (y as usize), d_set); } diff --git a/solution/0700-0799/0785.Is Graph Bipartite/Solution.rs b/solution/0700-0799/0785.Is Graph Bipartite/Solution.rs index 851fd0f028ad6..29bb619a8d7ed 100644 --- a/solution/0700-0799/0785.Is Graph Bipartite/Solution.rs +++ b/solution/0700-0799/0785.Is Graph Bipartite/Solution.rs @@ -17,7 +17,7 @@ impl Solution { v: usize, color: usize, color_vec: &mut Vec, - graph: &mut Vec> + graph: &mut Vec>, ) -> bool { color_vec[v] = color; for n in graph[v].clone() { diff --git a/solution/0700-0799/0791.Custom Sort String/Solution.rs b/solution/0700-0799/0791.Custom Sort String/Solution.rs index 488f21a12dafa..02abc04c88eeb 100644 --- a/solution/0700-0799/0791.Custom Sort String/Solution.rs +++ b/solution/0700-0799/0791.Custom Sort String/Solution.rs @@ -6,9 +6,9 @@ impl Solution { d[(c - b'a') as usize] = i; } let mut ans = s.chars().collect::>(); - ans.sort_by(|&a, &b| + ans.sort_by(|&a, &b| { d[((a as u8) - ('a' as u8)) as usize].cmp(&d[((b as u8) - ('a' as u8)) as usize]) - ); + }); ans.into_iter().collect() } } diff --git a/solution/0800-0899/0804.Unique Morse Code Words/Solution.rs b/solution/0800-0899/0804.Unique Morse Code Words/Solution.rs index 5fb35e4365e59..11d434d341207 100644 --- a/solution/0800-0899/0804.Unique Morse Code Words/Solution.rs +++ b/solution/0800-0899/0804.Unique Morse Code Words/Solution.rs @@ -2,32 +2,9 @@ use std::collections::HashSet; impl Solution { pub fn unique_morse_representations(words: Vec) -> i32 { const codes: [&str; 26] = [ - ".-", - "-...", - "-.-.", - "-..", - ".", - "..-.", - "--.", - "....", - "..", - ".---", - "-.-", - ".-..", - "--", - "-.", - "---", - ".--.", - "--.-", - ".-.", - "...", - "-", - "..-", - "...-", - ".--", - "-..-", - "-.--", - "--..", + ".-", "-...", "-.-.", "-..", ".", "..-.", "--.", "....", "..", ".---", "-.-", ".-..", + "--", "-.", "---", ".--.", "--.-", ".-.", "...", "-", "..-", "...-", ".--", "-..-", + "-.--", "--..", ]; words .iter() diff --git a/solution/0800-0899/0814.Binary Tree Pruning/Solution.rs b/solution/0800-0899/0814.Binary Tree Pruning/Solution.rs index a67851a47eef4..c629709b467fb 100644 --- a/solution/0800-0899/0814.Binary Tree Pruning/Solution.rs +++ b/solution/0800-0899/0814.Binary Tree Pruning/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn prune_tree(root: Option>>) -> Option>> { if root.is_none() { diff --git a/solution/0800-0899/0819.Most Common Word/Solution.rs b/solution/0800-0899/0819.Most Common Word/Solution.rs index 648405c9d045a..3d029a2d3e01b 100644 --- a/solution/0800-0899/0819.Most Common Word/Solution.rs +++ b/solution/0800-0899/0819.Most Common Word/Solution.rs @@ -1,4 +1,4 @@ -use std::collections::{ HashMap, HashSet }; +use std::collections::{HashMap, HashSet}; impl Solution { pub fn most_common_word(mut paragraph: String, banned: Vec) -> String { paragraph.make_ascii_lowercase(); @@ -14,6 +14,7 @@ impl Solution { map.into_iter() .max_by_key(|&(_, v)| v) .unwrap() - .0.to_string() + .0 + .to_string() } } diff --git a/solution/0800-0899/0827.Making A Large Island/Solution.rs b/solution/0800-0899/0827.Making A Large Island/Solution.rs index 9c0e74c30c0b4..c7bb9d577d19d 100644 --- a/solution/0800-0899/0827.Making A Large Island/Solution.rs +++ b/solution/0800-0899/0827.Making A Large Island/Solution.rs @@ -16,20 +16,19 @@ impl Solution { root: i32, i: usize, j: usize, - dirs: &[i32; 5] + dirs: &[i32; 5], ) -> i32 { p[i][j] = root; cnt[root as usize] += 1; for k in 0..4 { let x = (i as i32) + dirs[k]; let y = (j as i32) + dirs[k + 1]; - if - x >= 0 && - (x as usize) < grid.len() && - y >= 0 && - (y as usize) < grid.len() && - grid[x as usize][y as usize] == 1 && - p[x as usize][y as usize] == 0 + if x >= 0 + && (x as usize) < grid.len() + && y >= 0 + && (y as usize) < grid.len() + && grid[x as usize][y as usize] == 1 + && p[x as usize][y as usize] == 0 { dfs(grid, p, cnt, root, x as usize, y as usize, dirs); } diff --git a/solution/0800-0899/0872.Leaf-Similar Trees/Solution.rs b/solution/0800-0899/0872.Leaf-Similar Trees/Solution.rs index 5dad3ca599213..b26566fe67cc1 100644 --- a/solution/0800-0899/0872.Leaf-Similar Trees/Solution.rs +++ b/solution/0800-0899/0872.Leaf-Similar Trees/Solution.rs @@ -16,13 +16,13 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { #[allow(dead_code)] pub fn leaf_similar( root1: Option>>, - root2: Option>> + root2: Option>>, ) -> bool { let mut one_vec: Vec = Vec::new(); let mut two_vec: Vec = Vec::new(); @@ -50,7 +50,7 @@ impl Solution { #[allow(dead_code)] fn is_leaf_node(node: &Option>>) -> bool { - node.as_ref().unwrap().borrow().left.is_none() && - node.as_ref().unwrap().borrow().right.is_none() + node.as_ref().unwrap().borrow().left.is_none() + && node.as_ref().unwrap().borrow().right.is_none() } } diff --git a/solution/0800-0899/0883.Projection Area of 3D Shapes/Solution.rs b/solution/0800-0899/0883.Projection Area of 3D Shapes/Solution.rs index 33848f581c021..994358c09146e 100644 --- a/solution/0800-0899/0883.Projection Area of 3D Shapes/Solution.rs +++ b/solution/0800-0899/0883.Projection Area of 3D Shapes/Solution.rs @@ -2,26 +2,11 @@ impl Solution { pub fn projection_area(grid: Vec>) -> i32 { let xy: i32 = grid .iter() - .map( - |row| - row - .iter() - .filter(|&&v| v > 0) - .count() as i32 - ) - .sum(); - let yz: i32 = grid - .iter() - .map(|row| *row.iter().max().unwrap_or(&0)) + .map(|row| row.iter().filter(|&&v| v > 0).count() as i32) .sum(); + let yz: i32 = grid.iter().map(|row| *row.iter().max().unwrap_or(&0)).sum(); let zx: i32 = (0..grid[0].len()) - .map(|i| - grid - .iter() - .map(|row| row[i]) - .max() - .unwrap_or(0) - ) + .map(|i| grid.iter().map(|row| row[i]).max().unwrap_or(0)) .sum(); xy + yz + zx } diff --git a/solution/0800-0899/0894.All Possible Full Binary Trees/Solution.rs b/solution/0800-0899/0894.All Possible Full Binary Trees/Solution.rs index 921020b0d78fc..2503a45f409fd 100644 --- a/solution/0800-0899/0894.All Possible Full Binary Trees/Solution.rs +++ b/solution/0800-0899/0894.All Possible Full Binary Trees/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn all_possible_fbt(n: i32) -> Vec>>> { let mut f: Vec>>>>> = vec![None; (n + 1) as usize]; @@ -26,7 +26,7 @@ impl Solution { fn dfs( n: i32, - f: &mut Vec>>>>> + f: &mut Vec>>>>>, ) -> Vec>>> { if let Some(ref result) = f[n as usize] { return result.clone(); @@ -42,15 +42,11 @@ impl Solution { let j = n - 1 - i; for left in Self::dfs(i, f).iter() { for right in Self::dfs(j, f).iter() { - let new_node = Some( - Rc::new( - RefCell::new(TreeNode { - val: 0, - left: left.clone(), - right: right.clone(), - }) - ) - ); + let new_node = Some(Rc::new(RefCell::new(TreeNode { + val: 0, + left: left.clone(), + right: right.clone(), + }))); ans.push(new_node); } } diff --git a/solution/0900-0999/0901.Online Stock Span/README.md b/solution/0900-0999/0901.Online Stock Span/README.md index c123087c6253d..dcc278c313fe4 100644 --- a/solution/0900-0999/0901.Online Stock Span/README.md +++ b/solution/0900-0999/0901.Online Stock Span/README.md @@ -248,11 +248,7 @@ impl StockSpanner { self.stk.push_back((price, cnt)); cnt } -}/** - * Your StockSpanner object will be instantiated and called as such: - * let obj = StockSpanner::new(); - * let ret_1: i32 = obj.next(price); - */ +} ``` diff --git a/solution/0900-0999/0901.Online Stock Span/README_EN.md b/solution/0900-0999/0901.Online Stock Span/README_EN.md index 17f3649282438..3f9da2e505d5e 100644 --- a/solution/0900-0999/0901.Online Stock Span/README_EN.md +++ b/solution/0900-0999/0901.Online Stock Span/README_EN.md @@ -245,11 +245,7 @@ impl StockSpanner { self.stk.push_back((price, cnt)); cnt } -}/** - * Your StockSpanner object will be instantiated and called as such: - * let obj = StockSpanner::new(); - * let ret_1: i32 = obj.next(price); - */ +} ``` diff --git a/solution/0900-0999/0901.Online Stock Span/Solution.rs b/solution/0900-0999/0901.Online Stock Span/Solution.rs index 2f650c64d8432..e9d5332e0b880 100644 --- a/solution/0900-0999/0901.Online Stock Span/Solution.rs +++ b/solution/0900-0999/0901.Online Stock Span/Solution.rs @@ -22,8 +22,4 @@ impl StockSpanner { self.stk.push_back((price, cnt)); cnt } -}/** - * Your StockSpanner object will be instantiated and called as such: - * let obj = StockSpanner::new(); - * let ret_1: i32 = obj.next(price); - */ +} diff --git a/solution/0900-0999/0907.Sum of Subarray Minimums/Solution.rs b/solution/0900-0999/0907.Sum of Subarray Minimums/Solution.rs index 641a53ffa34f3..45474025bd83e 100644 --- a/solution/0900-0999/0907.Sum of Subarray Minimums/Solution.rs +++ b/solution/0900-0999/0907.Sum of Subarray Minimums/Solution.rs @@ -31,9 +31,8 @@ impl Solution { let MOD = 1_000_000_007; let mut ans: i64 = 0; for i in 0..n { - ans += - ((((right[i] - (i as i32)) * ((i as i32) - left[i])) as i64) * (arr[i] as i64)) % - MOD; + ans += ((((right[i] - (i as i32)) * ((i as i32) - left[i])) as i64) * (arr[i] as i64)) + % MOD; ans %= MOD; } ans as i32 diff --git a/solution/0900-0999/0933.Number of Recent Calls/README.md b/solution/0900-0999/0933.Number of Recent Calls/README.md index 0f770ef85a90f..ae78fc389c30c 100644 --- a/solution/0900-0999/0933.Number of Recent Calls/README.md +++ b/solution/0900-0999/0933.Number of Recent Calls/README.md @@ -234,11 +234,7 @@ impl RecentCounter { } self.queue.len() as i32 } -}/** - * Your RecentCounter object will be instantiated and called as such: - * let obj = RecentCounter::new(); - * let ret_1: i32 = obj.ping(t); - */ +} ``` #### JavaScript diff --git a/solution/0900-0999/0933.Number of Recent Calls/README_EN.md b/solution/0900-0999/0933.Number of Recent Calls/README_EN.md index a379382a28c62..3370a943c0690 100644 --- a/solution/0900-0999/0933.Number of Recent Calls/README_EN.md +++ b/solution/0900-0999/0933.Number of Recent Calls/README_EN.md @@ -226,11 +226,7 @@ impl RecentCounter { } self.queue.len() as i32 } -}/** - * Your RecentCounter object will be instantiated and called as such: - * let obj = RecentCounter::new(); - * let ret_1: i32 = obj.ping(t); - */ +} ``` #### JavaScript diff --git a/solution/0900-0999/0933.Number of Recent Calls/Solution.rs b/solution/0900-0999/0933.Number of Recent Calls/Solution.rs index aca9fc7fd11d7..b894f06efb8d6 100644 --- a/solution/0900-0999/0933.Number of Recent Calls/Solution.rs +++ b/solution/0900-0999/0933.Number of Recent Calls/Solution.rs @@ -24,8 +24,4 @@ impl RecentCounter { } self.queue.len() as i32 } -}/** - * Your RecentCounter object will be instantiated and called as such: - * let obj = RecentCounter::new(); - * let ret_1: i32 = obj.ping(t); - */ +} diff --git a/solution/0900-0999/0936.Stamping The Sequence/Solution.rs b/solution/0900-0999/0936.Stamping The Sequence/Solution.rs index ff776ece1453d..d6bb2e866e2b9 100644 --- a/solution/0900-0999/0936.Stamping The Sequence/Solution.rs +++ b/solution/0900-0999/0936.Stamping The Sequence/Solution.rs @@ -11,12 +11,7 @@ impl Solution { for i in 0..n - m + 1 { for j in 0..m { - if - target - .chars() - .nth(i + j) - .unwrap() == stamp.chars().nth(j).unwrap() - { + if target.chars().nth(i + j).unwrap() == stamp.chars().nth(j).unwrap() { indeg[i] -= 1; if indeg[i] == 0 { q.push_back(i); diff --git a/solution/0900-0999/0937.Reorder Data in Log Files/Solution.rs b/solution/0900-0999/0937.Reorder Data in Log Files/Solution.rs index 124f9ac142690..e094984c3ecc0 100644 --- a/solution/0900-0999/0937.Reorder Data in Log Files/Solution.rs +++ b/solution/0900-0999/0937.Reorder Data in Log Files/Solution.rs @@ -3,12 +3,10 @@ impl Solution { logs.sort_by(|s1, s2| { let (start1, content1) = s1.split_once(' ').unwrap(); let (start2, content2) = s2.split_once(' ').unwrap(); - match - ( - content1.chars().nth(0).unwrap().is_digit(10), - content2.chars().nth(0).unwrap().is_digit(10), - ) - { + match ( + content1.chars().nth(0).unwrap().is_digit(10), + content2.chars().nth(0).unwrap().is_digit(10), + ) { (true, true) => std::cmp::Ordering::Equal, (true, false) => std::cmp::Ordering::Greater, (false, true) => std::cmp::Ordering::Less, diff --git a/solution/0900-0999/0940.Distinct Subsequences II/Solution.rs b/solution/0900-0999/0940.Distinct Subsequences II/Solution.rs index 576d3554dc839..33e4526e44259 100644 --- a/solution/0900-0999/0940.Distinct Subsequences II/Solution.rs +++ b/solution/0900-0999/0940.Distinct Subsequences II/Solution.rs @@ -4,14 +4,13 @@ impl Solution { let mut dp = [0; 26]; for u in s.as_bytes() { let i = (u - &b'a') as usize; - dp[i] = - ({ - let mut sum = 0; - dp.iter().for_each(|&v| { - sum = (sum + v) % MOD; - }); - sum - }) + 1; + dp[i] = ({ + let mut sum = 0; + dp.iter().for_each(|&v| { + sum = (sum + v) % MOD; + }); + sum + }) + 1; } let mut res = 0; dp.iter().for_each(|&v| { diff --git a/solution/0900-0999/0942.DI String Match/Solution.rs b/solution/0900-0999/0942.DI String Match/Solution.rs index 0e439f5068053..3b1d3b05b7987 100644 --- a/solution/0900-0999/0942.DI String Match/Solution.rs +++ b/solution/0900-0999/0942.DI String Match/Solution.rs @@ -5,15 +5,13 @@ impl Solution { let mut res = Vec::with_capacity(n + 1); let (mut low, mut high) = (-1, (n + 1) as i32); for i in 0..n { - res.push( - if s[i] == b'I' { - low += 1; - low - } else { - high -= 1; - high - } - ); + res.push(if s[i] == b'I' { + low += 1; + low + } else { + high -= 1; + high + }); } res.push(low + 1); res diff --git a/solution/0900-0999/0953.Verifying an Alien Dictionary/Solution.rs b/solution/0900-0999/0953.Verifying an Alien Dictionary/Solution.rs index e23f47ce76eb1..fc4e9b1b4f9b3 100644 --- a/solution/0900-0999/0953.Verifying an Alien Dictionary/Solution.rs +++ b/solution/0900-0999/0953.Verifying an Alien Dictionary/Solution.rs @@ -3,13 +3,9 @@ impl Solution { pub fn is_alien_sorted(words: Vec, order: String) -> bool { let n = words.len(); let mut map = HashMap::new(); - order - .as_bytes() - .iter() - .enumerate() - .for_each(|(i, &v)| { - map.insert(v, i); - }); + order.as_bytes().iter().enumerate().for_each(|(i, &v)| { + map.insert(v, i); + }); for i in 1..n { let s1 = words[i - 1].as_bytes(); let s2 = words[i].as_bytes(); diff --git a/solution/0900-0999/0965.Univalued Binary Tree/Solution.rs b/solution/0900-0999/0965.Univalued Binary Tree/Solution.rs index 37c31036c0a51..0cd077656d7ad 100644 --- a/solution/0900-0999/0965.Univalued Binary Tree/Solution.rs +++ b/solution/0900-0999/0965.Univalued Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(val: i32, root: &Option>>) -> bool { if root.is_none() { diff --git a/solution/0900-0999/0973.K Closest Points to Origin/Solution.rs b/solution/0900-0999/0973.K Closest Points to Origin/Solution.rs index 50d765eeb3359..e02f320342f94 100644 --- a/solution/0900-0999/0973.K Closest Points to Origin/Solution.rs +++ b/solution/0900-0999/0973.K Closest Points to Origin/Solution.rs @@ -1,8 +1,7 @@ impl Solution { pub fn k_closest(mut points: Vec>, k: i32) -> Vec> { - points.sort_unstable_by(|a, b| { - (a[0].pow(2) + a[1].pow(2)).cmp(&(b[0].pow(2) + b[1].pow(2))) - }); + points + .sort_unstable_by(|a, b| (a[0].pow(2) + a[1].pow(2)).cmp(&(b[0].pow(2) + b[1].pow(2)))); points[0..k as usize].to_vec() } } diff --git a/solution/0900-0999/0986.Interval List Intersections/Solution.rs b/solution/0900-0999/0986.Interval List Intersections/Solution.rs index 5641a407b4bf3..5e104c8271a6b 100644 --- a/solution/0900-0999/0986.Interval List Intersections/Solution.rs +++ b/solution/0900-0999/0986.Interval List Intersections/Solution.rs @@ -1,7 +1,7 @@ impl Solution { pub fn interval_intersection( first_list: Vec>, - second_list: Vec> + second_list: Vec>, ) -> Vec> { let n = first_list.len(); let m = second_list.len(); diff --git a/solution/0900-0999/0994.Rotting Oranges/Solution.rs b/solution/0900-0999/0994.Rotting Oranges/Solution.rs index 0c6425dd07515..4e8479ffaadab 100644 --- a/solution/0900-0999/0994.Rotting Oranges/Solution.rs +++ b/solution/0900-0999/0994.Rotting Oranges/Solution.rs @@ -27,12 +27,11 @@ impl Solution { for d in 0..4 { let x = p[0] + dirs[d]; let y = p[1] + dirs[d + 1]; - if - x >= 0 && - x < (m as i32) && - y >= 0 && - y < (n as i32) && - grid[x as usize][y as usize] == 1 + if x >= 0 + && x < (m as i32) + && y >= 0 + && y < (n as i32) + && grid[x as usize][y as usize] == 1 { grid[x as usize][y as usize] = 2; q.push_back(vec![x, y]); diff --git a/solution/0900-0999/0998.Maximum Binary Tree II/Solution.rs b/solution/0900-0999/0998.Maximum Binary Tree II/Solution.rs index 936f488308102..9e66d812267f5 100644 --- a/solution/0900-0999/0998.Maximum Binary Tree II/Solution.rs +++ b/solution/0900-0999/0998.Maximum Binary Tree II/Solution.rs @@ -16,23 +16,19 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn insert_into_max_tree( mut root: Option>>, - val: i32 + val: i32, ) -> Option>> { if root.is_none() || root.as_ref().unwrap().as_ref().borrow().val < val { - return Some( - Rc::new( - RefCell::new(TreeNode { - val, - left: root.take(), - right: None, - }) - ) - ); + return Some(Rc::new(RefCell::new(TreeNode { + val, + left: root.take(), + right: None, + }))); } { let mut root = root.as_ref().unwrap().as_ref().borrow_mut(); diff --git a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.rs b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.rs index b2e38fb861192..dbbf9ef5afb39 100644 --- a/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.rs +++ b/solution/1000-1099/1008.Construct Binary Search Tree from Preorder Traversal/Solution.rs @@ -16,27 +16,23 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs( preorder: &Vec, next: &Vec, left: usize, - right: usize + right: usize, ) -> Option>> { if left >= right { return None; } - Some( - Rc::new( - RefCell::new(TreeNode { - val: preorder[left], - left: Self::dfs(preorder, next, left + 1, next[left]), - right: Self::dfs(preorder, next, next[left], right), - }) - ) - ) + Some(Rc::new(RefCell::new(TreeNode { + val: preorder[left], + left: Self::dfs(preorder, next, left + 1, next[left]), + right: Self::dfs(preorder, next, next[left], right), + }))) } pub fn bst_from_preorder(preorder: Vec) -> Option>> { diff --git a/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/Solution.rs b/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/Solution.rs index 46d412bfff947..0f8ae133c6a07 100644 --- a/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/Solution.rs +++ b/solution/1000-1099/1022.Sum of Root To Leaf Binary Numbers/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, mut num: i32) -> i32 { if root.is_none() { diff --git a/solution/1000-1099/1036.Escape a Large Maze/Solution.rs b/solution/1000-1099/1036.Escape a Large Maze/Solution.rs index c9a867f46d746..19e88060f539e 100644 --- a/solution/1000-1099/1036.Escape a Large Maze/Solution.rs +++ b/solution/1000-1099/1036.Escape a Large Maze/Solution.rs @@ -1,4 +1,4 @@ -use std::collections::{ HashSet, VecDeque }; +use std::collections::{HashSet, VecDeque}; const BOUNDARY: i32 = 1_000_000; const MAX: usize = 20000; @@ -28,13 +28,12 @@ fn bfs(block: &HashSet<(i32, i32)>, source: &Vec, target: &Vec) -> boo } for (dx, dy) in dir.iter() { let (nx, ny) = (x + dx, y + dy); - if - nx < 0 || - nx >= BOUNDARY || - ny < 0 || - ny >= BOUNDARY || - vis.contains(&(nx, ny)) || - block.contains(&(nx, ny)) + if nx < 0 + || nx >= BOUNDARY + || ny < 0 + || ny >= BOUNDARY + || vis.contains(&(nx, ny)) + || block.contains(&(nx, ny)) { continue; } diff --git a/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/Solution.rs b/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/Solution.rs index 3ddffcd4f253b..f2b6b87562fe8 100644 --- a/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/Solution.rs +++ b/solution/1000-1099/1038.Binary Search Tree to Greater Sum Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &mut Option>>, mut sum: i32) -> i32 { if let Some(node) = root { diff --git a/solution/1000-1099/1048.Longest String Chain/Solution.rs b/solution/1000-1099/1048.Longest String Chain/Solution.rs index e7d8d2e83b06f..bf786d2a85aaa 100644 --- a/solution/1000-1099/1048.Longest String Chain/Solution.rs +++ b/solution/1000-1099/1048.Longest String Chain/Solution.rs @@ -8,7 +8,7 @@ impl Solution { let mut map: HashMap = HashMap::new(); // Sort the words vector first - words.sort_by(|lhs, rhs| { lhs.len().cmp(&rhs.len()) }); + words.sort_by(|lhs, rhs| lhs.len().cmp(&rhs.len())); // Begin the "dp" process for w in words.iter() { diff --git a/solution/1000-1099/1049.Last Stone Weight II/Solution.rs b/solution/1000-1099/1049.Last Stone Weight II/Solution.rs index 34b1b380d17d7..458348470d241 100644 --- a/solution/1000-1099/1049.Last Stone Weight II/Solution.rs +++ b/solution/1000-1099/1049.Last Stone Weight II/Solution.rs @@ -19,7 +19,7 @@ impl Solution { } else { std::cmp::max( dp[i - 1][j], - dp[i - 1][j - (stones[i - 1] as usize)] + stones[i - 1] + dp[i - 1][j - (stones[i - 1] as usize)] + stones[i - 1], ) }; } diff --git a/solution/1000-1099/1094.Car Pooling/Solution.rs b/solution/1000-1099/1094.Car Pooling/Solution.rs index c30df69bcf6d2..f9641589c84c9 100644 --- a/solution/1000-1099/1094.Car Pooling/Solution.rs +++ b/solution/1000-1099/1094.Car Pooling/Solution.rs @@ -1,10 +1,6 @@ impl Solution { pub fn car_pooling(trips: Vec>, capacity: i32) -> bool { - let mx = trips - .iter() - .map(|e| e[2]) - .max() - .unwrap_or(0) as usize; + let mx = trips.iter().map(|e| e[2]).max().unwrap_or(0) as usize; let mut d = vec![0; mx + 1]; for trip in &trips { let (x, f, t) = (trip[0], trip[1] as usize, trip[2] as usize); diff --git a/solution/1100-1199/1102.Path With Maximum Minimum Value/Solution.rs b/solution/1100-1199/1102.Path With Maximum Minimum Value/Solution.rs index 96dc6c049fb55..b8852f771459b 100644 --- a/solution/1100-1199/1102.Path With Maximum Minimum Value/Solution.rs +++ b/solution/1100-1199/1102.Path With Maximum Minimum Value/Solution.rs @@ -61,12 +61,11 @@ impl Solution { for d in 0..4 { let x = (i as i32) + dirs[d]; let y = (j as i32) + dirs[d + 1]; - if - x >= 0 && - x < (m as i32) && - y >= 0 && - y < (n as i32) && - vis[x as usize][y as usize] + if x >= 0 + && x < (m as i32) + && y >= 0 + && y < (n as i32) + && vis[x as usize][y as usize] { uf.union((x as usize) * n + (y as usize), i * n + j); } diff --git a/solution/1100-1199/1106.Parsing A Boolean Expression/Solution.rs b/solution/1100-1199/1106.Parsing A Boolean Expression/Solution.rs index 0ac36ea63e96e..171b8443e5f59 100644 --- a/solution/1100-1199/1106.Parsing A Boolean Expression/Solution.rs +++ b/solution/1100-1199/1106.Parsing A Boolean Expression/Solution.rs @@ -19,18 +19,10 @@ impl Solution { res.push(!Self::dfs(i, expr)[0]); } b'&' => { - res.push( - Self::dfs(i, expr) - .iter() - .all(|v| *v) - ); + res.push(Self::dfs(i, expr).iter().all(|v| *v)); } b'|' => { - res.push( - Self::dfs(i, expr) - .iter() - .any(|v| *v) - ); + res.push(Self::dfs(i, expr).iter().any(|v| *v)); } _ => {} } diff --git a/solution/1100-1199/1197.Minimum Knight Moves/Solution.rs b/solution/1100-1199/1197.Minimum Knight Moves/Solution.rs index 0f58ce905594f..060baca804ce8 100644 --- a/solution/1100-1199/1197.Minimum Knight Moves/Solution.rs +++ b/solution/1100-1199/1197.Minimum Knight Moves/Solution.rs @@ -44,7 +44,7 @@ impl Solution { q: &mut VecDeque<(i32, i32, i32)>, i: i32, j: i32, - cur_step: i32 + cur_step: i32, ) { let next_step = cur_step + 1; for (dx, dy) in DIR { diff --git a/solution/1100-1199/1197.Minimum Knight Moves/Solution2.rs b/solution/1100-1199/1197.Minimum Knight Moves/Solution2.rs index 3152bf5c8a186..3c85113280d54 100644 --- a/solution/1100-1199/1197.Minimum Knight Moves/Solution2.rs +++ b/solution/1100-1199/1197.Minimum Knight Moves/Solution2.rs @@ -1,5 +1,5 @@ -use std::collections::VecDeque; use std::collections::HashMap; +use std::collections::VecDeque; const DIR: [(i32, i32); 8] = [ (-2, 1), @@ -53,17 +53,14 @@ impl Solution { fn extend( map_to: &mut HashMap, map_from: &mut HashMap, - cur_q: &mut VecDeque<(i32, i32)> + cur_q: &mut VecDeque<(i32, i32)>, ) -> i32 { let n = cur_q.len(); for _ in 0..n { let (i, j) = cur_q.front().unwrap().clone(); cur_q.pop_front(); // The cur_step here must exist - let cur_step = map_to - .get(&(601 * i + j)) - .unwrap() - .clone(); + let cur_step = map_to.get(&(601 * i + j)).unwrap().clone(); for (dx, dy) in DIR { let x = i + dx; let y = j + dy; @@ -75,14 +72,7 @@ impl Solution { // Check if this node has been visited by the other side if map_from.contains_key(&(601 * x + y)) { // We found the node - return ( - cur_step + - 1 + - map_from - .get(&(601 * x + y)) - .unwrap() - .clone() - ); + return (cur_step + 1 + map_from.get(&(601 * x + y)).unwrap().clone()); } // Otherwise, update map_to and push the new node to queue map_to.insert(601 * x + y, cur_step + 1); diff --git a/solution/1100-1199/1199.Minimum Time to Build Blocks/Solution.rs b/solution/1100-1199/1199.Minimum Time to Build Blocks/Solution.rs index 7bdf406113e54..64656fc33c853 100644 --- a/solution/1100-1199/1199.Minimum Time to Build Blocks/Solution.rs +++ b/solution/1100-1199/1199.Minimum Time to Build Blocks/Solution.rs @@ -1,5 +1,5 @@ -use std::collections::BinaryHeap; use std::cmp::Reverse; +use std::collections::BinaryHeap; impl Solution { pub fn min_build_time(blocks: Vec, split: i32) -> i32 { diff --git a/solution/1200-1299/1229.Meeting Scheduler/Solution.rs b/solution/1200-1299/1229.Meeting Scheduler/Solution.rs index c1f5735adda69..6d9f5c62d4718 100644 --- a/solution/1200-1299/1229.Meeting Scheduler/Solution.rs +++ b/solution/1200-1299/1229.Meeting Scheduler/Solution.rs @@ -3,14 +3,14 @@ impl Solution { pub fn min_available_duration( slots1: Vec>, slots2: Vec>, - duration: i32 + duration: i32, ) -> Vec { let mut slots1 = slots1; let mut slots2 = slots2; // First sort the two vectors based on the beginning time - slots1.sort_by(|lhs, rhs| { lhs[0].cmp(&rhs[0]) }); - slots2.sort_by(|lhs, rhs| { lhs[0].cmp(&rhs[0]) }); + slots1.sort_by(|lhs, rhs| lhs[0].cmp(&rhs[0])); + slots2.sort_by(|lhs, rhs| lhs[0].cmp(&rhs[0])); // Then traverse the two vector let mut i: usize = 0; diff --git a/solution/1200-1299/1244.Design A Leaderboard/Solution.rs b/solution/1200-1299/1244.Design A Leaderboard/Solution.rs index f73470eb8a54b..570c529d55156 100644 --- a/solution/1200-1299/1244.Design A Leaderboard/Solution.rs +++ b/solution/1200-1299/1244.Design A Leaderboard/Solution.rs @@ -18,7 +18,8 @@ impl Leaderboard { fn add_score(&mut self, player_id: i32, score: i32) { if self.record_map.contains_key(&player_id) { // The player exists, just add the score - self.record_map.insert(player_id, self.record_map.get(&player_id).unwrap() + score); + self.record_map + .insert(player_id, self.record_map.get(&player_id).unwrap() + score); } else { // Add the new player to the map self.record_map.insert(player_id, score); @@ -27,11 +28,8 @@ impl Leaderboard { #[allow(dead_code)] fn top(&self, k: i32) -> i32 { - let mut cur_vec: Vec<(i32, i32)> = self.record_map - .iter() - .map(|(k, v)| (*k, *v)) - .collect(); - cur_vec.sort_by(|lhs, rhs| { rhs.1.cmp(&lhs.1) }); + let mut cur_vec: Vec<(i32, i32)> = self.record_map.iter().map(|(k, v)| (*k, *v)).collect(); + cur_vec.sort_by(|lhs, rhs| rhs.1.cmp(&lhs.1)); // Iterate reversely for K let mut sum = 0; let mut i = 0; diff --git a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/Solution.rs b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/Solution.rs index 10621ee0149ac..20d7cb360ed90 100644 --- a/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/Solution.rs +++ b/solution/1200-1299/1282.Group the People Given the Group Size They Belong To/Solution.rs @@ -14,7 +14,7 @@ impl Solution { v[j..(j + i).min(v.len())] .iter() .map(|&x| x as i32) - .collect() + .collect(), ); } } diff --git a/solution/1300-1399/1302.Deepest Leaves Sum/Solution.rs b/solution/1300-1399/1302.Deepest Leaves Sum/Solution.rs index fae5f9833940d..d3599f0232a21 100644 --- a/solution/1300-1399/1302.Deepest Leaves Sum/Solution.rs +++ b/solution/1300-1399/1302.Deepest Leaves Sum/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>, depth: i32, max_depth: &mut i32, res: &mut i32) { if let Some(node) = root { diff --git a/solution/1300-1399/1305.All Elements in Two Binary Search Trees/Solution.rs b/solution/1300-1399/1305.All Elements in Two Binary Search Trees/Solution.rs index caa0e52613c00..b25f1d910e43c 100644 --- a/solution/1300-1399/1305.All Elements in Two Binary Search Trees/Solution.rs +++ b/solution/1300-1399/1305.All Elements in Two Binary Search Trees/Solution.rs @@ -21,7 +21,7 @@ use std::rc::Rc; impl Solution { pub fn get_all_elements( root1: Option>>, - root2: Option>> + root2: Option>>, ) -> Vec { fn dfs(root: &Option>>, t: &mut Vec) { if let Some(root) = root { diff --git a/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/Solution.rs b/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/Solution.rs index f70d5a5a07174..4b3dff5e33fec 100644 --- a/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/Solution.rs +++ b/solution/1300-1399/1326.Minimum Number of Taps to Open to Water a Garden/Solution.rs @@ -9,10 +9,8 @@ impl Solution { // Initialize the last vector for (i, &r) in ranges.iter().enumerate() { if (i as i32) - r >= 0 { - last[((i as i32) - r) as usize] = std::cmp::max( - last[((i as i32) - r) as usize], - (i as i32) + r - ); + last[((i as i32) - r) as usize] = + std::cmp::max(last[((i as i32) - r) as usize], (i as i32) + r); } else { last[0] = std::cmp::max(last[0], (i as i32) + r); } diff --git a/solution/1300-1399/1367.Linked List in Binary Tree/Solution.rs b/solution/1300-1399/1367.Linked List in Binary Tree/Solution.rs index f773172293156..237dd72e6e1f7 100644 --- a/solution/1300-1399/1367.Linked List in Binary Tree/Solution.rs +++ b/solution/1300-1399/1367.Linked List in Binary Tree/Solution.rs @@ -32,8 +32,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(head: &Option>, root: &Option>>) -> bool { if head.is_none() { @@ -55,9 +55,9 @@ impl Solution { return false; } let node = root.as_ref().unwrap().borrow(); - Self::dfs(head, root) || - Self::my_is_sub_path(head, &node.left) || - Self::my_is_sub_path(head, &node.right) + Self::dfs(head, root) + || Self::my_is_sub_path(head, &node.left) + || Self::my_is_sub_path(head, &node.right) } pub fn is_sub_path(head: Option>, root: Option>>) -> bool { diff --git a/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/Solution.rs b/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/Solution.rs index 7d06668c6adb6..70fa4f47fcccd 100644 --- a/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/Solution.rs +++ b/solution/1300-1399/1385.Find the Distance Value Between Two Arrays/Solution.rs @@ -14,9 +14,7 @@ impl Solution { right = mid; } } - if - i32::abs(num - arr2[left]) <= d || - (left != 0 && i32::abs(num - arr2[left - 1]) <= d) + if i32::abs(num - arr2[left]) <= d || (left != 0 && i32::abs(num - arr2[left - 1]) <= d) { continue; } diff --git a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.rs b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.rs index f87625ff2bf28..57666e2349af2 100644 --- a/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.rs +++ b/solution/1400-1499/1431.Kids With the Greatest Number of Candies/Solution.rs @@ -1,9 +1,6 @@ impl Solution { pub fn kids_with_candies(candies: Vec, extra_candies: i32) -> Vec { let max = *candies.iter().max().unwrap(); - candies - .iter() - .map(|v| v + extra_candies >= max) - .collect() + candies.iter().map(|v| v + extra_candies >= max).collect() } } diff --git a/solution/1400-1499/1436.Destination City/Solution.rs b/solution/1400-1499/1436.Destination City/Solution.rs index 9dd6b98cde9f7..bb33d41b8f055 100644 --- a/solution/1400-1499/1436.Destination City/Solution.rs +++ b/solution/1400-1499/1436.Destination City/Solution.rs @@ -1,10 +1,7 @@ use std::collections::HashSet; impl Solution { pub fn dest_city(paths: Vec>) -> String { - let set = paths - .iter() - .map(|v| &v[0]) - .collect::>(); + let set = paths.iter().map(|v| &v[0]).collect::>(); for path in paths.iter() { if !set.contains(&path[1]) { return path[1].clone(); diff --git a/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/Solution.rs b/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/Solution.rs index f4c1522fc60a9..d935b707aeaa4 100644 --- a/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/Solution.rs +++ b/solution/1400-1499/1457.Pseudo-Palindromic Paths in a Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn pseudo_palindromic_paths(root: Option>>) -> i32 { @@ -31,9 +31,8 @@ impl Solution { return if (mask & (mask - 1)) == 0 { 1 } else { 0 }; } - return ( - dfs(node.borrow().left.clone(), mask) + dfs(node.borrow().right.clone(), mask) - ); + return (dfs(node.borrow().left.clone(), mask) + + dfs(node.borrow().right.clone(), mask)); } 0 } diff --git a/solution/1400-1499/1458.Max Dot Product of Two Subsequences/Solution.rs b/solution/1400-1499/1458.Max Dot Product of Two Subsequences/Solution.rs index c9df56177fede..01e12026e66b8 100644 --- a/solution/1400-1499/1458.Max Dot Product of Two Subsequences/Solution.rs +++ b/solution/1400-1499/1458.Max Dot Product of Two Subsequences/Solution.rs @@ -10,7 +10,7 @@ impl Solution { for j in 1..=m { dp[i][j] = std::cmp::max( std::cmp::max(dp[i - 1][j], dp[i][j - 1]), - std::cmp::max(dp[i - 1][j - 1], 0) + nums1[i - 1] * nums2[j - 1] + std::cmp::max(dp[i - 1][j - 1], 0) + nums1[i - 1] * nums2[j - 1], ); } } diff --git a/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/Solution.rs b/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/Solution.rs index 42d7be05acc70..00aa9477fa31a 100644 --- a/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/Solution.rs +++ b/solution/1400-1499/1465.Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts/Solution.rs @@ -3,7 +3,7 @@ impl Solution { h: i32, w: i32, mut horizontal_cuts: Vec, - mut vertical_cuts: Vec + mut vertical_cuts: Vec, ) -> i32 { const MOD: i64 = 1_000_000_007; @@ -15,12 +15,18 @@ impl Solution { let mut x = i64::max( horizontal_cuts[0] as i64, - (h as i64) - (horizontal_cuts[m - 1] as i64) + (h as i64) - (horizontal_cuts[m - 1] as i64), + ); + let mut y = i64::max( + vertical_cuts[0] as i64, + (w as i64) - (vertical_cuts[n - 1] as i64), ); - let mut y = i64::max(vertical_cuts[0] as i64, (w as i64) - (vertical_cuts[n - 1] as i64)); for i in 1..m { - x = i64::max(x, (horizontal_cuts[i] as i64) - (horizontal_cuts[i - 1] as i64)); + x = i64::max( + x, + (horizontal_cuts[i] as i64) - (horizontal_cuts[i - 1] as i64), + ); } for i in 1..n { diff --git a/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/Solution.rs b/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/Solution.rs index ed9d48f032cab..0e1f387e70073 100644 --- a/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/Solution.rs +++ b/solution/1500-1599/1599.Maximum Profit of Operating a Centennial Wheel/Solution.rs @@ -2,7 +2,7 @@ impl Solution { pub fn min_operations_max_profit( customers: Vec, boarding_cost: i32, - running_cost: i32 + running_cost: i32, ) -> i32 { let mut ans = -1; let mut mx = 0; diff --git a/solution/1600-1699/1603.Design Parking System/README.md b/solution/1600-1699/1603.Design Parking System/README.md index 9d5dfa2c081b7..6b57f48a95b37 100644 --- a/solution/1600-1699/1603.Design Parking System/README.md +++ b/solution/1600-1699/1603.Design Parking System/README.md @@ -223,11 +223,7 @@ impl ParkingSystem { self.count[i] -= 1; true } -}/** - * Your ParkingSystem object will be instantiated and called as such: - * let obj = ParkingSystem::new(big, medium, small); - * let ret_1: bool = obj.add_car(carType); - */ +} ``` #### C# diff --git a/solution/1600-1699/1603.Design Parking System/README_EN.md b/solution/1600-1699/1603.Design Parking System/README_EN.md index 24c8d10263240..db3c957bd405d 100644 --- a/solution/1600-1699/1603.Design Parking System/README_EN.md +++ b/solution/1600-1699/1603.Design Parking System/README_EN.md @@ -217,11 +217,7 @@ impl ParkingSystem { self.count[i] -= 1; true } -}/** - * Your ParkingSystem object will be instantiated and called as such: - * let obj = ParkingSystem::new(big, medium, small); - * let ret_1: bool = obj.add_car(carType); - */ +} ``` #### C# diff --git a/solution/1600-1699/1603.Design Parking System/Solution.rs b/solution/1600-1699/1603.Design Parking System/Solution.rs index 5c159357185bc..bb55e867617bf 100644 --- a/solution/1600-1699/1603.Design Parking System/Solution.rs +++ b/solution/1600-1699/1603.Design Parking System/Solution.rs @@ -21,8 +21,4 @@ impl ParkingSystem { self.count[i] -= 1; true } -}/** - * Your ParkingSystem object will be instantiated and called as such: - * let obj = ParkingSystem::new(big, medium, small); - * let ret_1: bool = obj.add_car(carType); - */ +} diff --git a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/Solution.rs b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/Solution.rs index 0fdc93421b69d..a1e26a3d48b25 100644 --- a/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/Solution.rs +++ b/solution/1600-1699/1647.Minimum Deletions to Make Character Frequencies Unique/Solution.rs @@ -8,7 +8,7 @@ impl Solution { cnt[((c as u8) - ('a' as u8)) as usize] += 1; } - cnt.sort_by(|&lhs, &rhs| { rhs.cmp(&lhs) }); + cnt.sort_by(|&lhs, &rhs| rhs.cmp(&lhs)); for i in 1..26 { while cnt[i] >= cnt[i - 1] && cnt[i] > 0 { diff --git a/solution/1600-1699/1656.Design an Ordered Stream/README.md b/solution/1600-1699/1656.Design an Ordered Stream/README.md index 831c49b4e8dd7..90082a6cdbcb7 100644 --- a/solution/1600-1699/1656.Design an Ordered Stream/README.md +++ b/solution/1600-1699/1656.Design an Ordered Stream/README.md @@ -252,11 +252,7 @@ impl OrderedStream { } res } -}/** - * Your OrderedStream object will be instantiated and called as such: - * let obj = OrderedStream::new(n); - * let ret_1: Vec = obj.insert(idKey, value); - */ +} ``` diff --git a/solution/1600-1699/1656.Design an Ordered Stream/README_EN.md b/solution/1600-1699/1656.Design an Ordered Stream/README_EN.md index f41c3070e563d..c34c2f0bba412 100644 --- a/solution/1600-1699/1656.Design an Ordered Stream/README_EN.md +++ b/solution/1600-1699/1656.Design an Ordered Stream/README_EN.md @@ -247,11 +247,7 @@ impl OrderedStream { } res } -}/** - * Your OrderedStream object will be instantiated and called as such: - * let obj = OrderedStream::new(n); - * let ret_1: Vec = obj.insert(idKey, value); - */ +} ``` diff --git a/solution/1600-1699/1656.Design an Ordered Stream/Solution.rs b/solution/1600-1699/1656.Design an Ordered Stream/Solution.rs index 1af99533a70d7..28b729154d4e5 100644 --- a/solution/1600-1699/1656.Design an Ordered Stream/Solution.rs +++ b/solution/1600-1699/1656.Design an Ordered Stream/Solution.rs @@ -9,7 +9,10 @@ struct OrderedStream { */ impl OrderedStream { fn new(n: i32) -> Self { - Self { ptr: 0, vals: vec![None; n as usize] } + Self { + ptr: 0, + vals: vec![None; n as usize], + } } fn insert(&mut self, id_key: i32, value: String) -> Vec { @@ -25,8 +28,4 @@ impl OrderedStream { } res } -}/** - * Your OrderedStream object will be instantiated and called as such: - * let obj = OrderedStream::new(n); - * let ret_1: Vec = obj.insert(idKey, value); - */ +} diff --git a/solution/1600-1699/1668.Maximum Repeating Substring/Solution.rs b/solution/1600-1699/1668.Maximum Repeating Substring/Solution.rs index e9f0a39799fb8..1635642d6c4e9 100644 --- a/solution/1600-1699/1668.Maximum Repeating Substring/Solution.rs +++ b/solution/1600-1699/1668.Maximum Repeating Substring/Solution.rs @@ -9,7 +9,11 @@ impl Solution { for i in 0..=n - m { let s = &sequence[i..i + m]; if s == word { - dp[i] = (if (i as i32) - (m as i32) < 0 { 0 } else { dp[i - m] }) + 1; + dp[i] = (if (i as i32) - (m as i32) < 0 { + 0 + } else { + dp[i - m] + }) + 1; } } *dp.iter().max().unwrap() diff --git a/solution/1600-1699/1672.Richest Customer Wealth/Solution.rs b/solution/1600-1699/1672.Richest Customer Wealth/Solution.rs index 2ba7dfc30e5cf..f10a81621fedb 100644 --- a/solution/1600-1699/1672.Richest Customer Wealth/Solution.rs +++ b/solution/1600-1699/1672.Richest Customer Wealth/Solution.rs @@ -1,9 +1,5 @@ impl Solution { pub fn maximum_wealth(accounts: Vec>) -> i32 { - accounts - .iter() - .map(|v| v.iter().sum()) - .max() - .unwrap() + accounts.iter().map(|v| v.iter().sum()).max().unwrap() } } diff --git a/solution/1600-1699/1678.Goal Parser Interpretation/Solution2.rs b/solution/1600-1699/1678.Goal Parser Interpretation/Solution2.rs index 73f8139f01e3b..68f04333498f2 100644 --- a/solution/1600-1699/1678.Goal Parser Interpretation/Solution2.rs +++ b/solution/1600-1699/1678.Goal Parser Interpretation/Solution2.rs @@ -8,7 +8,11 @@ impl Solution { } if bs[i] == b'(' { ans.push_str({ - if bs[i + 1] == b')' { "o" } else { "al" } + if bs[i + 1] == b')' { + "o" + } else { + "al" + } }); } } diff --git a/solution/1600-1699/1694.Reformat Phone Number/Solution.rs b/solution/1600-1699/1694.Reformat Phone Number/Solution.rs index e0a557cda7688..1fd805c3c9400 100644 --- a/solution/1600-1699/1694.Reformat Phone Number/Solution.rs +++ b/solution/1600-1699/1694.Reformat Phone Number/Solution.rs @@ -1,9 +1,6 @@ impl Solution { pub fn reformat_number(number: String) -> String { - let cs: Vec = number - .chars() - .filter(|&c| c != ' ' && c != '-') - .collect(); + let cs: Vec = number.chars().filter(|&c| c != ' ' && c != '-').collect(); let n = cs.len(); cs.iter() .enumerate() diff --git a/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/Solution.rs b/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/Solution.rs index 93f26dfe59109..c303621288f17 100644 --- a/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/Solution.rs +++ b/solution/1600-1699/1697.Checking Existence of Edge Length Limited Paths/Solution.rs @@ -3,7 +3,7 @@ impl Solution { pub fn distance_limited_paths_exist( n: i32, edge_list: Vec>, - queries: Vec> + queries: Vec>, ) -> Vec { let mut disjoint_set: Vec = vec![0; n as usize]; let mut ans_vec: Vec = vec![false; queries.len()]; @@ -36,7 +36,7 @@ impl Solution { Solution::union( edge_list[edge_idx][0] as usize, edge_list[edge_idx][1] as usize, - &mut disjoint_set + &mut disjoint_set, ); edge_idx += 1; } diff --git a/solution/1700-1799/1702.Maximum Binary String After Change/Solution.rs b/solution/1700-1799/1702.Maximum Binary String After Change/Solution.rs index 80adf090abddf..1259aee7d46d3 100644 --- a/solution/1700-1799/1702.Maximum Binary String After Change/Solution.rs +++ b/solution/1700-1799/1702.Maximum Binary String After Change/Solution.rs @@ -1,13 +1,13 @@ impl Solution { pub fn maximum_binary_string(binary: String) -> String { if let Some(k) = binary.find('0') { - let k = - k + - binary[k + 1..] - .chars() - .filter(|&c| c == '0') - .count(); - return format!("{}{}{}", "1".repeat(k), "0", "1".repeat(binary.len() - k - 1)); + let k = k + binary[k + 1..].chars().filter(|&c| c == '0').count(); + return format!( + "{}{}{}", + "1".repeat(k), + "0", + "1".repeat(binary.len() - k - 1) + ); } binary } diff --git a/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/Solution.rs b/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/Solution.rs index 93df3b2e2f96e..75112174d82d0 100644 --- a/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/Solution.rs +++ b/solution/1700-1799/1769.Minimum Number of Operations to Move All Balls to Each Box/Solution.rs @@ -18,9 +18,6 @@ impl Solution { } right[i] = right[i + 1] + count; } - (0..n) - .into_iter() - .map(|i| left[i] + right[i]) - .collect() + (0..n).into_iter().map(|i| left[i] + right[i]).collect() } } diff --git a/solution/1700-1799/1773.Count Items Matching a Rule/Solution.rs b/solution/1700-1799/1773.Count Items Matching a Rule/Solution.rs index 3c2f860a1ecfd..641af5a81f21f 100644 --- a/solution/1700-1799/1773.Count Items Matching a Rule/Solution.rs +++ b/solution/1700-1799/1773.Count Items Matching a Rule/Solution.rs @@ -1,9 +1,12 @@ impl Solution { pub fn count_matches(items: Vec>, rule_key: String, rule_value: String) -> i32 { - let key = if rule_key == "type" { 0 } else if rule_key == "color" { 1 } else { 2 }; - items - .iter() - .filter(|v| v[key] == rule_value) - .count() as i32 + let key = if rule_key == "type" { + 0 + } else if rule_key == "color" { + 1 + } else { + 2 + }; + items.iter().filter(|v| v[key] == rule_value).count() as i32 } } diff --git a/solution/1700-1799/1797.Design Authentication Manager/README.md b/solution/1700-1799/1797.Design Authentication Manager/README.md index f85159f9fa63a..d5ccda981f821 100644 --- a/solution/1700-1799/1797.Design Authentication Manager/README.md +++ b/solution/1700-1799/1797.Design Authentication Manager/README.md @@ -319,13 +319,7 @@ impl AuthenticationManager { .filter(|&time| *time > current_time) .count() as i32 } -}/** - * Your AuthenticationManager object will be instantiated and called as such: - * let obj = AuthenticationManager::new(timeToLive); - * obj.generate(tokenId, currentTime); - * obj.renew(tokenId, currentTime); - * let ret_3: i32 = obj.count_unexpired_tokens(currentTime); - */ +} ``` diff --git a/solution/1700-1799/1797.Design Authentication Manager/README_EN.md b/solution/1700-1799/1797.Design Authentication Manager/README_EN.md index 1880a71ded482..49fc711dd514b 100644 --- a/solution/1700-1799/1797.Design Authentication Manager/README_EN.md +++ b/solution/1700-1799/1797.Design Authentication Manager/README_EN.md @@ -317,13 +317,7 @@ impl AuthenticationManager { .filter(|&time| *time > current_time) .count() as i32 } -}/** - * Your AuthenticationManager object will be instantiated and called as such: - * let obj = AuthenticationManager::new(timeToLive); - * obj.generate(tokenId, currentTime); - * obj.renew(tokenId, currentTime); - * let ret_3: i32 = obj.count_unexpired_tokens(currentTime); - */ +} ``` diff --git a/solution/1700-1799/1797.Design Authentication Manager/Solution.rs b/solution/1700-1799/1797.Design Authentication Manager/Solution.rs index fdadb4bf07161..f108aef55c32c 100644 --- a/solution/1700-1799/1797.Design Authentication Manager/Solution.rs +++ b/solution/1700-1799/1797.Design Authentication Manager/Solution.rs @@ -33,10 +33,4 @@ impl AuthenticationManager { .filter(|&time| *time > current_time) .count() as i32 } -}/** - * Your AuthenticationManager object will be instantiated and called as such: - * let obj = AuthenticationManager::new(timeToLive); - * obj.generate(tokenId, currentTime); - * obj.renew(tokenId, currentTime); - * let ret_3: i32 = obj.count_unexpired_tokens(currentTime); - */ +} diff --git a/solution/1800-1899/1862.Sum of Floored Pairs/Solution.rs b/solution/1800-1899/1862.Sum of Floored Pairs/Solution.rs index dbbcd65c143bc..e936147083c90 100644 --- a/solution/1800-1899/1862.Sum of Floored Pairs/Solution.rs +++ b/solution/1800-1899/1862.Sum of Floored Pairs/Solution.rs @@ -22,11 +22,10 @@ impl Solution { if cnt[y] > 0 { let mut d = 1; while d * y <= (mx as usize) { - ans += - ((cnt[y] as i64) * - (d as i64) * - (s[std::cmp::min(mx as usize, d * y + y - 1)] - s[d * y - 1])) % - (MOD as i64); + ans += ((cnt[y] as i64) + * (d as i64) + * (s[std::cmp::min(mx as usize, d * y + y - 1)] - s[d * y - 1])) + % (MOD as i64); ans %= MOD as i64; d += 1; } diff --git a/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/Solution.rs b/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/Solution.rs index 37cf29fe22368..6d4bcf926b24c 100644 --- a/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/Solution.rs +++ b/solution/1800-1899/1894.Find the Student that Will Replace the Chalk/Solution.rs @@ -1,9 +1,6 @@ impl Solution { pub fn chalk_replacer(chalk: Vec, k: i32) -> i32 { - let mut s: i64 = chalk - .iter() - .map(|&x| x as i64) - .sum(); + let mut s: i64 = chalk.iter().map(|&x| x as i64).sum(); let mut k = (k as i64) % s; for (i, &x) in chalk.iter().enumerate() { if k < (x as i64) { diff --git a/solution/1900-1999/1920.Build Array from Permutation/Solution.rs b/solution/1900-1999/1920.Build Array from Permutation/Solution.rs index 9102b43d9b80c..4a31e9c504e42 100644 --- a/solution/1900-1999/1920.Build Array from Permutation/Solution.rs +++ b/solution/1900-1999/1920.Build Array from Permutation/Solution.rs @@ -1,7 +1,5 @@ impl Solution { pub fn build_array(nums: Vec) -> Vec { - nums.iter() - .map(|&v| nums[v as usize]) - .collect() + nums.iter().map(|&v| nums[v as usize]).collect() } } diff --git a/solution/1900-1999/1971.Find if Path Exists in Graph/Solution2.rs b/solution/1900-1999/1971.Find if Path Exists in Graph/Solution2.rs index c1be44eb3a894..575018a990fce 100644 --- a/solution/1900-1999/1971.Find if Path Exists in Graph/Solution2.rs +++ b/solution/1900-1999/1971.Find if Path Exists in Graph/Solution2.rs @@ -1,4 +1,4 @@ -use std::collections::{ HashSet, VecDeque }; +use std::collections::{HashSet, VecDeque}; impl Solution { pub fn valid_path(n: i32, edges: Vec>, source: i32, destination: i32) -> bool { diff --git a/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/Solution.rs b/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/Solution.rs index 2cca0b52ea2a0..9d5c8d80788cb 100644 --- a/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/Solution.rs +++ b/solution/2000-2099/2003.Smallest Missing Genetic Value in Each Subtree/Solution.rs @@ -5,7 +5,7 @@ impl Solution { vis: &mut Vec, has: &mut Vec, g: &Vec>, - nums: &Vec + nums: &Vec, ) { if vis[i] { return; diff --git a/solution/2000-2099/2032.Two Out of Three/Solution.rs b/solution/2000-2099/2032.Two Out of Three/Solution.rs index cd043ba4152f3..8303269c37727 100644 --- a/solution/2000-2099/2032.Two Out of Three/Solution.rs +++ b/solution/2000-2099/2032.Two Out of Three/Solution.rs @@ -24,14 +24,11 @@ impl Solution { count[v as usize] += 1; }); let mut ans = Vec::new(); - count - .iter() - .enumerate() - .for_each(|(i, v)| { - if *v >= 2 { - ans.push(i as i32); - } - }); + count.iter().enumerate().for_each(|(i, v)| { + if *v >= 2 { + ans.push(i as i32); + } + }); ans } } diff --git a/solution/2000-2099/2043.Simple Bank System/README.md b/solution/2000-2099/2043.Simple Bank System/README.md index d71e4e5638c44..fb34740dc1053 100644 --- a/solution/2000-2099/2043.Simple Bank System/README.md +++ b/solution/2000-2099/2043.Simple Bank System/README.md @@ -357,13 +357,7 @@ impl Bank { self.balance[account - 1] -= money; true } -}/** - * Your Bank object will be instantiated and called as such: - * let obj = Bank::new(balance); - * let ret_1: bool = obj.transfer(account1, account2, money); - * let ret_2: bool = obj.deposit(account, money); - * let ret_3: bool = obj.withdraw(account, money); - */ +} ``` diff --git a/solution/2000-2099/2043.Simple Bank System/README_EN.md b/solution/2000-2099/2043.Simple Bank System/README_EN.md index 6af2e06b68385..f726e4e8f0bfa 100644 --- a/solution/2000-2099/2043.Simple Bank System/README_EN.md +++ b/solution/2000-2099/2043.Simple Bank System/README_EN.md @@ -355,13 +355,7 @@ impl Bank { self.balance[account - 1] -= money; true } -}/** - * Your Bank object will be instantiated and called as such: - * let obj = Bank::new(balance); - * let ret_1: bool = obj.transfer(account1, account2, money); - * let ret_2: bool = obj.deposit(account, money); - * let ret_3: bool = obj.withdraw(account, money); - */ +} ``` diff --git a/solution/2000-2099/2043.Simple Bank System/Solution.rs b/solution/2000-2099/2043.Simple Bank System/Solution.rs index a32cd0507fa8b..ea99307091c7d 100644 --- a/solution/2000-2099/2043.Simple Bank System/Solution.rs +++ b/solution/2000-2099/2043.Simple Bank System/Solution.rs @@ -44,10 +44,4 @@ impl Bank { self.balance[account - 1] -= money; true } -}/** - * Your Bank object will be instantiated and called as such: - * let obj = Bank::new(balance); - * let ret_1: bool = obj.transfer(account1, account2, money); - * let ret_2: bool = obj.deposit(account, money); - * let ret_3: bool = obj.withdraw(account, money); - */ +} diff --git a/solution/2100-2199/2103.Rings and Rods/Solution.rs b/solution/2100-2199/2103.Rings and Rods/Solution.rs index 00aa8e1c74ac0..377dfb1ad7f62 100644 --- a/solution/2100-2199/2103.Rings and Rods/Solution.rs +++ b/solution/2100-2199/2103.Rings and Rods/Solution.rs @@ -15,9 +15,6 @@ impl Solution { mask[j] |= d[c]; } - mask - .iter() - .filter(|&&x| x == 7) - .count() as i32 + mask.iter().filter(|&&x| x == 7).count() as i32 } } diff --git a/solution/2100-2199/2125.Number of Laser Beams in a Bank/Solution.rs b/solution/2100-2199/2125.Number of Laser Beams in a Bank/Solution.rs index 834ef62c07513..f8e893fad2ece 100644 --- a/solution/2100-2199/2125.Number of Laser Beams in a Bank/Solution.rs +++ b/solution/2100-2199/2125.Number of Laser Beams in a Bank/Solution.rs @@ -3,10 +3,7 @@ impl Solution { let mut ans = 0; let mut pre = 0; for row in bank { - let cur = row - .chars() - .filter(|&c| c == '1') - .count() as i32; + let cur = row.chars().filter(|&c| c == '1').count() as i32; if cur > 0 { ans += pre * cur; pre = cur; diff --git a/solution/2100-2199/2132.Stamping the Grid/Solution.rs b/solution/2100-2199/2132.Stamping the Grid/Solution.rs index d9c365f2670e2..d4e6200dbda2d 100644 --- a/solution/2100-2199/2132.Stamping the Grid/Solution.rs +++ b/solution/2100-2199/2132.Stamping the Grid/Solution.rs @@ -28,9 +28,8 @@ impl Solution { // Check the bound if x <= n && y <= m { // If the region can be sticked (All cells are empty, which means the sum will be zero) - if - prefix_vec[x][y] - prefix_vec[x][j] - prefix_vec[i][y] + prefix_vec[i][j] == - 0 + if prefix_vec[x][y] - prefix_vec[x][j] - prefix_vec[i][y] + prefix_vec[i][j] + == 0 { // Update the difference vector diff_vec[i][j] += 1; diff --git a/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/Solution.rs b/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/Solution.rs index ad29456ae0a9c..36b440adcc76d 100644 --- a/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/Solution.rs +++ b/solution/2100-2199/2134.Minimum Swaps to Group All 1's Together II/Solution.rs @@ -8,9 +8,8 @@ impl Solution { } let mut mx: i32 = cnt; for i in k..(n as i32) + k { - cnt += - nums[(i % (n as i32)) as usize] - - nums[((i - k + (n as i32)) % (n as i32)) as usize]; + cnt += nums[(i % (n as i32)) as usize] + - nums[((i - k + (n as i32)) % (n as i32)) as usize]; mx = mx.max(cnt); } return k - mx; diff --git a/solution/2100-2199/2141.Maximum Running Time of N Computers/Solution.rs b/solution/2100-2199/2141.Maximum Running Time of N Computers/Solution.rs index e4a5c48986648..343c2f29230ba 100644 --- a/solution/2100-2199/2141.Maximum Running Time of N Computers/Solution.rs +++ b/solution/2100-2199/2141.Maximum Running Time of N Computers/Solution.rs @@ -32,9 +32,8 @@ impl Solution { ret = (cur_height as i64) + diff; break; } else { - extra_sum -= - ((batteries[i + 1] - batteries[i]) as i64) * - ((i - ((m - n) as usize) + 1) as i64); + extra_sum -= ((batteries[i + 1] - batteries[i]) as i64) + * ((i - ((m - n) as usize) + 1) as i64); ret = batteries[i + 1] as i64; } diff --git a/solution/2100-2199/2185.Counting Words With a Given Prefix/Solution.rs b/solution/2100-2199/2185.Counting Words With a Given Prefix/Solution.rs index 73e470df904db..266dcbcd8fd49 100644 --- a/solution/2100-2199/2185.Counting Words With a Given Prefix/Solution.rs +++ b/solution/2100-2199/2185.Counting Words With a Given Prefix/Solution.rs @@ -1,8 +1,5 @@ impl Solution { pub fn prefix_count(words: Vec, pref: String) -> i32 { - words - .iter() - .filter(|s| s.starts_with(&pref)) - .count() as i32 + words.iter().filter(|s| s.starts_with(&pref)).count() as i32 } } diff --git a/solution/2100-2199/2196.Create Binary Tree From Descriptions/Solution.rs b/solution/2100-2199/2196.Create Binary Tree From Descriptions/Solution.rs index 34126739f0c77..26f76b3b38919 100644 --- a/solution/2100-2199/2196.Create Binary Tree From Descriptions/Solution.rs +++ b/solution/2100-2199/2196.Create Binary Tree From Descriptions/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::HashMap; +use std::rc::Rc; impl Solution { fn dfs(val: i32, map: &HashMap) -> Option>> { if val == 0 { diff --git a/solution/2200-2299/2212.Maximum Points in an Archery Competition/Solution.rs b/solution/2200-2299/2212.Maximum Points in an Archery Competition/Solution.rs index 88bb1160b4a2b..873b627c72634 100644 --- a/solution/2200-2299/2212.Maximum Points in an Archery Competition/Solution.rs +++ b/solution/2200-2299/2212.Maximum Points in an Archery Competition/Solution.rs @@ -8,14 +8,12 @@ impl Solution { if count > alice_arrows[i] { res[i] = alice_arrows[i] + 1; let r2 = Self::dfs(alice_arrows, res, count - alice_arrows[i] - 1, i - 1); - if - r2 - .iter() - .enumerate() - .map(|(i, v)| if v > &0 { i } else { 0 }) - .sum::() > - r1 - .iter() + if r2 + .iter() + .enumerate() + .map(|(i, v)| if v > &0 { i } else { 0 }) + .sum::() + > r1.iter() .enumerate() .map(|(i, v)| if v > &0 { i } else { 0 }) .sum::() diff --git a/solution/2200-2299/2215.Find the Difference of Two Arrays/Solution.rs b/solution/2200-2299/2215.Find the Difference of Two Arrays/Solution.rs index 069fa832bc00c..266b739780104 100644 --- a/solution/2200-2299/2215.Find the Difference of Two Arrays/Solution.rs +++ b/solution/2200-2299/2215.Find the Difference of Two Arrays/Solution.rs @@ -13,7 +13,7 @@ impl Solution { .filter_map(|&v| if nums1.contains(&v) { None } else { Some(v) }) .collect::>() .into_iter() - .collect() + .collect(), ] } } diff --git a/solution/2200-2299/2217.Find Palindrome With Fixed Length/Solution.rs b/solution/2200-2299/2217.Find Palindrome With Fixed Length/Solution.rs index a0ddbf3ca2a3f..5b7dbe8defe04 100644 --- a/solution/2200-2299/2217.Find Palindrome With Fixed Length/Solution.rs +++ b/solution/2200-2299/2217.Find Palindrome With Fixed Length/Solution.rs @@ -13,15 +13,14 @@ impl Solution { format!( "{}{}", num, - num - .to_string() + num.to_string() .chars() .rev() .skip(if is_odd { 1 } else { 0 }) .collect::() ) - .parse() - .unwrap() + .parse() + .unwrap() }) .collect() } diff --git a/solution/2200-2299/2236.Root Equals Sum of Children/Solution.rs b/solution/2200-2299/2236.Root Equals Sum of Children/Solution.rs index 6404d313a9e1f..a49ebf36b4ded 100644 --- a/solution/2200-2299/2236.Root Equals Sum of Children/Solution.rs +++ b/solution/2200-2299/2236.Root Equals Sum of Children/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { pub fn check_tree(root: Option>>) -> bool { let node = root.as_ref().unwrap().borrow(); diff --git a/solution/2200-2299/2251.Number of Flowers in Full Bloom/Solution.rs b/solution/2200-2299/2251.Number of Flowers in Full Bloom/Solution.rs index e57c70df980be..8808acf012f97 100644 --- a/solution/2200-2299/2251.Number of Flowers in Full Bloom/Solution.rs +++ b/solution/2200-2299/2251.Number of Flowers in Full Bloom/Solution.rs @@ -6,13 +6,9 @@ impl Solution { let n = people.len(); // First sort the people vector based on the first item - let mut people: Vec<(usize, i32)> = people - .into_iter() - .enumerate() - .map(|x| x) - .collect(); + let mut people: Vec<(usize, i32)> = people.into_iter().enumerate().map(|x| x).collect(); - people.sort_by(|lhs, rhs| { lhs.1.cmp(&rhs.1) }); + people.sort_by(|lhs, rhs| lhs.1.cmp(&rhs.1)); // Initialize the difference vector let mut diff = BTreeMap::new(); diff --git a/solution/2200-2299/2293.Min Max Game/Solution.rs b/solution/2200-2299/2293.Min Max Game/Solution.rs index 208564da9af0d..9e22625c7241b 100644 --- a/solution/2200-2299/2293.Min Max Game/Solution.rs +++ b/solution/2200-2299/2293.Min Max Game/Solution.rs @@ -6,7 +6,7 @@ impl Solution { for i in 0..n { nums[i] = (if (i & 1) == 1 { i32::max } else { i32::min })( nums[i << 1], - nums[(i << 1) | 1] + nums[(i << 1) | 1], ); } } diff --git a/solution/2300-2399/2331.Evaluate Boolean Binary Tree/Solution.rs b/solution/2300-2399/2331.Evaluate Boolean Binary Tree/Solution.rs index d58089742e4a8..f613c59be70f1 100644 --- a/solution/2300-2399/2331.Evaluate Boolean Binary Tree/Solution.rs +++ b/solution/2300-2399/2331.Evaluate Boolean Binary Tree/Solution.rs @@ -16,8 +16,8 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; +use std::rc::Rc; impl Solution { fn dfs(root: &Option>>) -> bool { let root = root.as_ref().unwrap().as_ref().borrow(); diff --git a/solution/2300-2399/2336.Smallest Number in Infinite Set/README.md b/solution/2300-2399/2336.Smallest Number in Infinite Set/README.md index f9a584bdf213d..63504a6dfc7ab 100644 --- a/solution/2300-2399/2336.Smallest Number in Infinite Set/README.md +++ b/solution/2300-2399/2336.Smallest Number in Infinite Set/README.md @@ -904,12 +904,7 @@ impl SmallestInfiniteSet { fn add_back(&mut self, num: i32) { self.s.insert(num); } -}/** - * Your SmallestInfiniteSet object will be instantiated and called as such: - * let obj = SmallestInfiniteSet::new(); - * let ret_1: i32 = obj.pop_smallest(); - * obj.add_back(num); - */ +} ``` diff --git a/solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md b/solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md index 34fd5ed3e89a4..dbbe5ddd9f4e3 100644 --- a/solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md +++ b/solution/2300-2399/2336.Smallest Number in Infinite Set/README_EN.md @@ -903,12 +903,7 @@ impl SmallestInfiniteSet { fn add_back(&mut self, num: i32) { self.s.insert(num); } -}/** - * Your SmallestInfiniteSet object will be instantiated and called as such: - * let obj = SmallestInfiniteSet::new(); - * let ret_1: i32 = obj.pop_smallest(); - * obj.add_back(num); - */ +} ``` diff --git a/solution/2300-2399/2336.Smallest Number in Infinite Set/Solution.rs b/solution/2300-2399/2336.Smallest Number in Infinite Set/Solution.rs index 546e320d68304..a8758d94b6d0a 100644 --- a/solution/2300-2399/2336.Smallest Number in Infinite Set/Solution.rs +++ b/solution/2300-2399/2336.Smallest Number in Infinite Set/Solution.rs @@ -22,9 +22,4 @@ impl SmallestInfiniteSet { fn add_back(&mut self, num: i32) { self.s.insert(num); } -}/** - * Your SmallestInfiniteSet object will be instantiated and called as such: - * let obj = SmallestInfiniteSet::new(); - * let ret_1: i32 = obj.pop_smallest(); - * obj.add_back(num); - */ +} diff --git a/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/Solution.rs b/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/Solution.rs index c2de3bb8c8f44..e1b1fef2415d8 100644 --- a/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/Solution.rs +++ b/solution/2300-2399/2383.Minimum Hours of Training to Win a Competition/Solution.rs @@ -3,7 +3,7 @@ impl Solution { mut initial_energy: i32, mut initial_experience: i32, energy: Vec, - experience: Vec + experience: Vec, ) -> i32 { let n = energy.len(); let mut res = 0; diff --git a/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/Solution.rs b/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/Solution.rs index e0974dbeb5099..6373258868b36 100644 --- a/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/Solution.rs +++ b/solution/2400-2499/2415.Reverse Odd Levels of Binary Tree/Solution.rs @@ -16,27 +16,23 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { fn create_tree(vals: &Vec>, i: usize, j: usize) -> Option>> { if i == vals.len() { return None; } - Some( - Rc::new( - RefCell::new(TreeNode { - val: vals[i][j], - left: Self::create_tree(vals, i + 1, j * 2), - right: Self::create_tree(vals, i + 1, j * 2 + 1), - }) - ) - ) + Some(Rc::new(RefCell::new(TreeNode { + val: vals[i][j], + left: Self::create_tree(vals, i + 1, j * 2), + right: Self::create_tree(vals, i + 1, j * 2 + 1), + }))) } pub fn reverse_odd_levels( - root: Option>> + root: Option>>, ) -> Option>> { let mut queue = VecDeque::new(); queue.push_back(root); diff --git a/solution/2400-2499/2418.Sort the People/Solution.rs b/solution/2400-2499/2418.Sort the People/Solution.rs index 55943f6892813..c22aa495a7838 100644 --- a/solution/2400-2499/2418.Sort the People/Solution.rs +++ b/solution/2400-2499/2418.Sort the People/Solution.rs @@ -2,9 +2,6 @@ impl Solution { pub fn sort_people(names: Vec, heights: Vec) -> Vec { let mut combine: Vec<(String, i32)> = names.into_iter().zip(heights.into_iter()).collect(); combine.sort_by(|a, b| b.1.cmp(&a.1)); - combine - .iter() - .map(|s| s.0.clone()) - .collect() + combine.iter().map(|s| s.0.clone()).collect() } } diff --git a/solution/2400-2499/2443.Sum of Number and Its Reverse/Solution.rs b/solution/2400-2499/2443.Sum of Number and Its Reverse/Solution.rs index c12f69e92235f..40b6333b5d9f0 100644 --- a/solution/2400-2499/2443.Sum of Number and Its Reverse/Solution.rs +++ b/solution/2400-2499/2443.Sum of Number and Its Reverse/Solution.rs @@ -1,17 +1,15 @@ impl Solution { pub fn sum_of_number_and_reverse(num: i32) -> bool { for i in 0..=num { - if - i + - ({ - let mut t = i; - let mut j = 0; - while t > 0 { - j = j * 10 + (t % 10); - t /= 10; - } - j - }) == num + if i + ({ + let mut t = i; + let mut j = 0; + while t > 0 { + j = j * 10 + (t % 10); + t /= 10; + } + j + }) == num { return true; } diff --git a/solution/2400-2499/2448.Minimum Cost to Make Array Equal/Solution.rs b/solution/2400-2499/2448.Minimum Cost to Make Array Equal/Solution.rs index c48200d961381..e5b9eaa0bf975 100644 --- a/solution/2400-2499/2448.Minimum Cost to Make Array Equal/Solution.rs +++ b/solution/2400-2499/2448.Minimum Cost to Make Array Equal/Solution.rs @@ -4,7 +4,7 @@ impl Solution { let mut zip_vec: Vec<_> = nums.into_iter().zip(cost.into_iter()).collect(); // Sort the zip vector based on nums - zip_vec.sort_by(|lhs, rhs| { lhs.0.cmp(&rhs.0) }); + zip_vec.sort_by(|lhs, rhs| lhs.0.cmp(&rhs.0)); let (nums, cost): (Vec, Vec) = zip_vec.into_iter().unzip(); diff --git a/solution/2400-2499/2451.Odd String Difference/Solution2.rs b/solution/2400-2499/2451.Odd String Difference/Solution2.rs index 7c34c996a806a..e1e2deddd50c4 100644 --- a/solution/2400-2499/2451.Odd String Difference/Solution2.rs +++ b/solution/2400-2499/2451.Odd String Difference/Solution2.rs @@ -11,14 +11,9 @@ impl Solution { .map(|(current, next)| (next - current) as i32) .collect(); - let s: String = bytes - .iter() - .map(|&b| char::from(b as u8)) - .collect(); + let s: String = bytes.iter().map(|&b| char::from(b as u8)).collect(); - h.entry(s) - .or_insert(vec![]) - .push(w); + h.entry(s).or_insert(vec![]).push(w); } for strs in h.values() { diff --git a/solution/2400-2499/2452.Words Within Two Edits of Dictionary/Solution.rs b/solution/2400-2499/2452.Words Within Two Edits of Dictionary/Solution.rs index 5af085ccc6be5..2edb37aa27d92 100644 --- a/solution/2400-2499/2452.Words Within Two Edits of Dictionary/Solution.rs +++ b/solution/2400-2499/2452.Words Within Two Edits of Dictionary/Solution.rs @@ -3,13 +3,9 @@ impl Solution { queries .into_iter() .filter(|s| { - dictionary.iter().any(|t| { - s - .chars() - .zip(t.chars()) - .filter(|&(a, b)| a != b) - .count() < 3 - }) + dictionary + .iter() + .any(|t| s.chars().zip(t.chars()).filter(|&(a, b)| a != b).count() < 3) }) .collect() } diff --git a/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/Solution2.rs b/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/Solution2.rs index d7ba0d1a73556..fcf7fdb6cd19e 100644 --- a/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/Solution2.rs +++ b/solution/2400-2499/2455.Average Value of Even Numbers That Are Divisible by Three/Solution2.rs @@ -1,10 +1,6 @@ impl Solution { pub fn average_value(nums: Vec) -> i32 { - let filtered_nums: Vec = nums - .iter() - .cloned() - .filter(|&n| n % 6 == 0) - .collect(); + let filtered_nums: Vec = nums.iter().cloned().filter(|&n| n % 6 == 0).collect(); if filtered_nums.is_empty() { return 0; diff --git a/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/Solution.rs b/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/Solution.rs index 4047ad8a5a1b6..ccf20366a003f 100644 --- a/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/Solution.rs +++ b/solution/2400-2499/2471.Minimum Number of Operations to Sort a Binary Tree by Level/Solution.rs @@ -16,9 +16,9 @@ // } // } // } -use std::rc::Rc; use std::cell::RefCell; use std::collections::VecDeque; +use std::rc::Rc; impl Solution { pub fn minimum_operations(root: Option>>) -> i32 { let mut queue = VecDeque::new(); diff --git a/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/Solution2.rs b/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/Solution2.rs index e45c3d8d4a370..14ba6814a7de0 100644 --- a/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/Solution2.rs +++ b/solution/2500-2599/2511.Maximum Enemy Forts That Can Be Captured/Solution2.rs @@ -3,19 +3,12 @@ impl Solution { let mut ans = 0; let mut i = 0; - while - let Some((idx, &value)) = forts + while let Some((idx, &value)) = forts.iter().enumerate().skip(i).find(|&(_, &x)| x != 0) { + if let Some((jdx, _)) = forts .iter() .enumerate() - .skip(i) + .skip(idx + 1) .find(|&(_, &x)| x != 0) - { - if - let Some((jdx, _)) = forts - .iter() - .enumerate() - .skip(idx + 1) - .find(|&(_, &x)| x != 0) { if value + forts[jdx] == 0 { ans = ans.max(jdx - idx - 1); diff --git a/solution/2500-2599/2512.Reward Top K Students/Solution.rs b/solution/2500-2599/2512.Reward Top K Students/Solution.rs index 00890be7a7c70..f1987361646cf 100644 --- a/solution/2500-2599/2512.Reward Top K Students/Solution.rs +++ b/solution/2500-2599/2512.Reward Top K Students/Solution.rs @@ -1,11 +1,11 @@ -use std::collections::{ HashMap, HashSet }; +use std::collections::{HashMap, HashSet}; impl Solution { pub fn top_students( positive_feedback: Vec, negative_feedback: Vec, report: Vec, student_id: Vec, - k: i32 + k: i32, ) -> Vec { let n = student_id.len(); let ps = positive_feedback.iter().collect::>(); @@ -31,9 +31,6 @@ impl Solution { } b.1.cmp(&a.1) }); - t.iter() - .map(|v| v.0) - .collect::>() - [0..k as usize].to_vec() + t.iter().map(|v| v.0).collect::>()[0..k as usize].to_vec() } } diff --git a/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/Solution.rs b/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/Solution.rs index 14c0f92154042..f9f0ac0910815 100644 --- a/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/Solution.rs +++ b/solution/2500-2599/2515.Shortest Distance to Target String in a Circular Array/Solution.rs @@ -3,9 +3,7 @@ impl Solution { let start_index = start_index as usize; let n = words.len(); for i in 0..=n >> 1 { - if - words[(start_index - i + n) % n] == target || - words[(start_index + i) % n] == target + if words[(start_index - i + n) % n] == target || words[(start_index + i) % n] == target { return i as i32; } diff --git a/solution/2500-2599/2520.Count the Digits That Divide a Number/Solution2.rs b/solution/2500-2599/2520.Count the Digits That Divide a Number/Solution2.rs index 9283826149bd4..89d5f0d0cba9d 100644 --- a/solution/2500-2599/2520.Count the Digits That Divide a Number/Solution2.rs +++ b/solution/2500-2599/2520.Count the Digits That Divide a Number/Solution2.rs @@ -1,7 +1,6 @@ impl Solution { pub fn count_digits(num: i32) -> i32 { - num - .to_string() + num.to_string() .chars() .filter(|&c| c != '0') .filter(|&c| num % (c.to_digit(10).unwrap() as i32) == 0) diff --git a/solution/2500-2599/2525.Categorize Box According to Criteria/Solution2.rs b/solution/2500-2599/2525.Categorize Box According to Criteria/Solution2.rs index c8e16b8876123..9df92e09b19d3 100644 --- a/solution/2500-2599/2525.Categorize Box According to Criteria/Solution2.rs +++ b/solution/2500-2599/2525.Categorize Box According to Criteria/Solution2.rs @@ -1,11 +1,10 @@ impl Solution { pub fn categorize_box(length: i32, width: i32, height: i32, mass: i32) -> String { let v = length * width * height; - let bulky = - length >= 10000 || - width >= 10000 || - height >= 10000 || - (length as i64) * (width as i64) * (height as i64) >= 1000000000; + let bulky = length >= 10000 + || width >= 10000 + || height >= 10000 + || (length as i64) * (width as i64) * (height as i64) >= 1000000000; let heavy = mass >= 100; diff --git a/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/Solution2.rs b/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/Solution2.rs index 622f661a54fe3..b8e10bd1a5aea 100644 --- a/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/Solution2.rs +++ b/solution/2500-2599/2535.Difference Between Element Sum and Digit Sum of an Array/Solution2.rs @@ -3,13 +3,12 @@ impl Solution { let a: i32 = nums.iter().sum(); let b: i32 = nums .iter() - .map(|&n| - n - .to_string() + .map(|&n| { + n.to_string() .chars() .map(|c| c.to_digit(10).unwrap() as i32) .sum::() - ) + }) .sum(); (a - b).abs() } diff --git a/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/Solution.rs b/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/Solution.rs index 88cea21652f3f..2188b990ed06e 100644 --- a/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/Solution.rs +++ b/solution/2500-2599/2541.Minimum Operations to Make Array Equal II/Solution.rs @@ -3,12 +3,7 @@ impl Solution { let k = k as i64; let n = nums1.len(); if k == 0 { - return if - nums1 - .iter() - .enumerate() - .all(|(i, &v)| v == nums2[i]) - { + return if nums1.iter().enumerate().all(|(i, &v)| v == nums2[i]) { 0 } else { -1 diff --git a/solution/2500-2599/2553.Separate the Digits in an Array/Solution.rs b/solution/2500-2599/2553.Separate the Digits in an Array/Solution.rs index b8c7593f39cdc..3822e78d36270 100644 --- a/solution/2500-2599/2553.Separate the Digits in an Array/Solution.rs +++ b/solution/2500-2599/2553.Separate the Digits in an Array/Solution.rs @@ -8,9 +8,7 @@ impl Solution { t.push(num % 10); num /= 10; } - t.into_iter() - .rev() - .for_each(|v| ans.push(v)); + t.into_iter().rev().for_each(|v| ans.push(v)); } ans } diff --git a/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/Solution.rs b/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/Solution.rs index 9f694214fbcbb..fb7f839d904e0 100644 --- a/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/Solution.rs +++ b/solution/2500-2599/2566.Maximum Difference by Remapping a Digit/Solution.rs @@ -1,7 +1,10 @@ impl Solution { pub fn min_max_difference(num: i32) -> i32 { let s = num.to_string(); - let min = s.replace(char::from(s.as_bytes()[0]), "0").parse::().unwrap(); + let min = s + .replace(char::from(s.as_bytes()[0]), "0") + .parse::() + .unwrap(); for &c in s.as_bytes() { if c != b'9' { return s.replace(c, "9").parse().unwrap() - min; diff --git a/solution/2500-2599/2567.Minimum Score by Changing Two Elements/Solution.rs b/solution/2500-2599/2567.Minimum Score by Changing Two Elements/Solution.rs index 1a8f9ea9ef89e..0146c812fe049 100644 --- a/solution/2500-2599/2567.Minimum Score by Changing Two Elements/Solution.rs +++ b/solution/2500-2599/2567.Minimum Score by Changing Two Elements/Solution.rs @@ -2,6 +2,8 @@ impl Solution { pub fn minimize_sum(mut nums: Vec) -> i32 { nums.sort(); let n = nums.len(); - (nums[n - 1] - nums[2]).min(nums[n - 2] - nums[1]).min(nums[n - 3] - nums[0]) + (nums[n - 1] - nums[2]) + .min(nums[n - 2] - nums[1]) + .min(nums[n - 3] - nums[0]) } } diff --git a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/Solution.rs b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/Solution.rs index ae93d70adf5d0..13dfa746ac135 100644 --- a/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/Solution.rs +++ b/solution/2500-2599/2586.Count the Number of Vowel Strings in Range/Solution.rs @@ -1,8 +1,7 @@ impl Solution { pub fn vowel_strings(words: Vec, left: i32, right: i32) -> i32 { - let check = |c: u8| -> bool { - c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u' - }; + let check = + |c: u8| -> bool { c == b'a' || c == b'e' || c == b'i' || c == b'o' || c == b'u' }; let mut ans = 0; for i in left..=right { diff --git a/solution/2500-2599/2590.Design a Todo List/Solution.rs b/solution/2500-2599/2590.Design a Todo List/Solution.rs index e46160ba09c27..f90aacf922dcd 100644 --- a/solution/2500-2599/2590.Design a Todo List/Solution.rs +++ b/solution/2500-2599/2590.Design a Todo List/Solution.rs @@ -1,4 +1,4 @@ -use std::collections::{ HashMap, HashSet }; +use std::collections::{HashMap, HashSet}; #[derive(Clone)] struct Task { @@ -28,19 +28,16 @@ impl TodoList { user_id: i32, task_description: String, due_date: i32, - tags: Vec + tags: Vec, ) -> i32 { if self.user_map.contains_key(&user_id) { // Just add the task - self.user_map - .get_mut(&user_id) - .unwrap() - .push(Task { - task_id: self.id, - description: task_description, - tags: tags.into_iter().collect::>(), - due_date, - }); + self.user_map.get_mut(&user_id).unwrap().push(Task { + task_id: self.id, + description: task_description, + tags: tags.into_iter().collect::>(), + due_date, + }); // Increase the global id self.id += 1; return self.id - 1; @@ -53,41 +50,34 @@ impl TodoList { description: task_description, tags: tags.into_iter().collect::>(), due_date, - }] + }], ); self.id += 1; self.id - 1 } fn get_all_tasks(&self, user_id: i32) -> Vec { - if - !self.user_map.contains_key(&user_id) || - self.user_map.get(&user_id).unwrap().is_empty() + if !self.user_map.contains_key(&user_id) || self.user_map.get(&user_id).unwrap().is_empty() { return vec![]; } // Get the task vector let mut ret_vec = (*self.user_map.get(&user_id).unwrap()).clone(); // Sort by due date - ret_vec.sort_by(|lhs, rhs| { lhs.due_date.cmp(&rhs.due_date) }); + ret_vec.sort_by(|lhs, rhs| lhs.due_date.cmp(&rhs.due_date)); // Return the description vector - ret_vec - .into_iter() - .map(|x| x.description) - .collect() + ret_vec.into_iter().map(|x| x.description).collect() } fn get_tasks_for_tag(&self, user_id: i32, tag: String) -> Vec { - if - !self.user_map.contains_key(&user_id) || - self.user_map.get(&user_id).unwrap().is_empty() + if !self.user_map.contains_key(&user_id) || self.user_map.get(&user_id).unwrap().is_empty() { return vec![]; } // Get the task vector let mut ret_vec = (*self.user_map.get(&user_id).unwrap()).clone(); // Sort by due date - ret_vec.sort_by(|lhs, rhs| { lhs.due_date.cmp(&rhs.due_date) }); + ret_vec.sort_by(|lhs, rhs| lhs.due_date.cmp(&rhs.due_date)); // Return the description vector ret_vec .into_iter() @@ -97,9 +87,7 @@ impl TodoList { } fn complete_task(&mut self, user_id: i32, task_id: i32) { - if - !self.user_map.contains_key(&user_id) || - self.user_map.get(&user_id).unwrap().is_empty() + if !self.user_map.contains_key(&user_id) || self.user_map.get(&user_id).unwrap().is_empty() { return; } diff --git a/solution/2600-2699/2600.K Items With the Maximum Sum/Solution.rs b/solution/2600-2699/2600.K Items With the Maximum Sum/Solution.rs index 19093962f4269..0ab8fc319b6b9 100644 --- a/solution/2600-2699/2600.K Items With the Maximum Sum/Solution.rs +++ b/solution/2600-2699/2600.K Items With the Maximum Sum/Solution.rs @@ -3,7 +3,7 @@ impl Solution { num_ones: i32, num_zeros: i32, num_neg_ones: i32, - k: i32 + k: i32, ) -> i32 { if num_ones > k { return k; diff --git a/solution/2600-2699/2643.Row With Maximum Ones/Solution.rs b/solution/2600-2699/2643.Row With Maximum Ones/Solution.rs index 7fab8e2e5b7b7..da124bf28e74f 100644 --- a/solution/2600-2699/2643.Row With Maximum Ones/Solution.rs +++ b/solution/2600-2699/2643.Row With Maximum Ones/Solution.rs @@ -3,10 +3,7 @@ impl Solution { let mut ans = vec![0, 0]; for (i, row) in mat.iter().enumerate() { - let cnt = row - .iter() - .filter(|&v| *v == 1) - .count() as i32; + let cnt = row.iter().filter(|&v| *v == 1).count() as i32; if ans[1] < cnt { ans[0] = i as i32; ans[1] = cnt; diff --git a/solution/2600-2699/2652.Sum Multiples/Solution2.rs b/solution/2600-2699/2652.Sum Multiples/Solution2.rs index a98ac33349f2c..d4dcd77c75b26 100644 --- a/solution/2600-2699/2652.Sum Multiples/Solution2.rs +++ b/solution/2600-2699/2652.Sum Multiples/Solution2.rs @@ -1,5 +1,7 @@ impl Solution { pub fn sum_of_multiples(n: i32) -> i32 { - (1..=n).filter(|&x| (x % 3 == 0 || x % 5 == 0 || x % 7 == 0)).sum() + (1..=n) + .filter(|&x| (x % 3 == 0 || x % 5 == 0 || x % 7 == 0)) + .sum() } } diff --git "a/solution/2600-2699/2664.The Knight\342\200\231s Tour/Solution.rs" "b/solution/2600-2699/2664.The Knight\342\200\231s Tour/Solution.rs" index 33d46ceb7c2e9..39abda9797ef7 100644 --- "a/solution/2600-2699/2664.The Knight\342\200\231s Tour/Solution.rs" +++ "b/solution/2600-2699/2664.The Knight\342\200\231s Tour/Solution.rs" @@ -12,7 +12,7 @@ impl Solution { m: i32, n: i32, dirs: &[i32; 9], - ok: &mut bool + ok: &mut bool, ) { if g[i][j] == m * n - 1 { *ok = true; diff --git a/solution/2600-2699/2671.Frequency Tracker/README.md b/solution/2600-2699/2671.Frequency Tracker/README.md index 032e6d06ffbbf..27037cc25471f 100644 --- a/solution/2600-2699/2671.Frequency Tracker/README.md +++ b/solution/2600-2699/2671.Frequency Tracker/README.md @@ -347,13 +347,7 @@ impl FrequencyTracker { fn has_frequency(&self, frequency: i32) -> bool { self.freq.get(&frequency).map_or(false, |&freq| freq > 0) } -}/** - * Your FrequencyTracker object will be instantiated and called as such: - * let obj = FrequencyTracker::new(); - * obj.add(number); - * obj.delete_one(number); - * let ret_3: bool = obj.has_frequency(frequency); - */ +} ``` diff --git a/solution/2600-2699/2671.Frequency Tracker/README_EN.md b/solution/2600-2699/2671.Frequency Tracker/README_EN.md index c1475cc1081c2..d93a0cf39c49a 100644 --- a/solution/2600-2699/2671.Frequency Tracker/README_EN.md +++ b/solution/2600-2699/2671.Frequency Tracker/README_EN.md @@ -348,13 +348,7 @@ impl FrequencyTracker { fn has_frequency(&self, frequency: i32) -> bool { self.freq.get(&frequency).map_or(false, |&freq| freq > 0) } -}/** - * Your FrequencyTracker object will be instantiated and called as such: - * let obj = FrequencyTracker::new(); - * obj.add(number); - * obj.delete_one(number); - * let ret_3: bool = obj.has_frequency(frequency); - */ +} ``` diff --git a/solution/2600-2699/2671.Frequency Tracker/Solution.rs b/solution/2600-2699/2671.Frequency Tracker/Solution.rs index b16aea8ad6705..bccd8c6152327 100644 --- a/solution/2600-2699/2671.Frequency Tracker/Solution.rs +++ b/solution/2600-2699/2671.Frequency Tracker/Solution.rs @@ -43,10 +43,4 @@ impl FrequencyTracker { fn has_frequency(&self, frequency: i32) -> bool { self.freq.get(&frequency).map_or(false, |&freq| freq > 0) } -}/** - * Your FrequencyTracker object will be instantiated and called as such: - * let obj = FrequencyTracker::new(); - * obj.add(number); - * obj.delete_one(number); - * let ret_3: bool = obj.has_frequency(frequency); - */ +} diff --git a/solution/2600-2699/2679.Sum in a Matrix/Solution.rs b/solution/2600-2699/2679.Sum in a Matrix/Solution.rs index 8cdc9052996eb..5c57ed969f65a 100644 --- a/solution/2600-2699/2679.Sum in a Matrix/Solution.rs +++ b/solution/2600-2699/2679.Sum in a Matrix/Solution.rs @@ -4,13 +4,7 @@ impl Solution { row.sort(); } (0..nums[0].len()) - .map(|col| - nums - .iter() - .map(|row| row[col]) - .max() - .unwrap() - ) + .map(|col| nums.iter().map(|row| row[col]).max().unwrap()) .sum() } } diff --git a/solution/2700-2799/2742.Painting the Walls/Solution.rs b/solution/2700-2799/2742.Painting the Walls/Solution.rs index d517f74a2d2c7..5f8d002c55500 100644 --- a/solution/2700-2799/2742.Painting the Walls/Solution.rs +++ b/solution/2700-2799/2742.Painting the Walls/Solution.rs @@ -13,7 +13,7 @@ impl Solution { j: i32, n: i32, time: &Vec, - cost: &Vec + cost: &Vec, ) -> i32 { if n - i <= j - n { // All the remaining walls can be printed at no cost @@ -28,9 +28,9 @@ impl Solution { if record_vec[i as usize][j as usize] == -1 { // This record hasn't been written record_vec[i as usize][j as usize] = std::cmp::min( - Self::dfs(record_vec, i + 1, j + time[i as usize], n, time, cost) + - cost[i as usize], - Self::dfs(record_vec, i + 1, j - 1, n, time, cost) + Self::dfs(record_vec, i + 1, j + time[i as usize], n, time, cost) + + cost[i as usize], + Self::dfs(record_vec, i + 1, j - 1, n, time, cost), ); } record_vec[i as usize][j as usize] diff --git a/solution/2700-2799/2798.Number of Employees Who Met the Target/Solution.rs b/solution/2700-2799/2798.Number of Employees Who Met the Target/Solution.rs index 0fdfea18d0c4f..1d9eeb00e89d6 100644 --- a/solution/2700-2799/2798.Number of Employees Who Met the Target/Solution.rs +++ b/solution/2700-2799/2798.Number of Employees Who Met the Target/Solution.rs @@ -1,8 +1,5 @@ impl Solution { pub fn number_of_employees_who_met_target(hours: Vec, target: i32) -> i32 { - hours - .iter() - .filter(|&x| *x >= target) - .count() as i32 + hours.iter().filter(|&x| *x >= target).count() as i32 } } diff --git a/solution/2800-2899/2812.Find the Safest Path in a Grid/Solution.rs b/solution/2800-2899/2812.Find the Safest Path in a Grid/Solution.rs index 7ea01852f3f85..e8bd4761d71bf 100644 --- a/solution/2800-2899/2812.Find the Safest Path in a Grid/Solution.rs +++ b/solution/2800-2899/2812.Find the Safest Path in a Grid/Solution.rs @@ -6,11 +6,11 @@ impl Solution { } vis[i][j] = true; let n = g.len(); - (i == n - 1 && j == n - 1) || - (i != 0 && Self::dfs(i - 1, j, v, g, vis)) || - (i != n - 1 && Self::dfs(i + 1, j, v, g, vis)) || - (j != 0 && Self::dfs(i, j - 1, v, g, vis)) || - (j != n - 1 && Self::dfs(i, j + 1, v, g, vis)) + (i == n - 1 && j == n - 1) + || (i != 0 && Self::dfs(i - 1, j, v, g, vis)) + || (i != n - 1 && Self::dfs(i + 1, j, v, g, vis)) + || (j != 0 && Self::dfs(i, j - 1, v, g, vis)) + || (j != n - 1 && Self::dfs(i, j + 1, v, g, vis)) } pub fn maximum_safeness_factor(grid: Vec>) -> i32 { diff --git a/solution/2800-2899/2828.Check if a String Is an Acronym of Words/Solution.rs b/solution/2800-2899/2828.Check if a String Is an Acronym of Words/Solution.rs index 3e1c7d53caac3..d9c10c5875512 100644 --- a/solution/2800-2899/2828.Check if a String Is an Acronym of Words/Solution.rs +++ b/solution/2800-2899/2828.Check if a String Is an Acronym of Words/Solution.rs @@ -3,6 +3,7 @@ impl Solution { words .iter() .map(|w| w.chars().next().unwrap_or_default()) - .collect::() == s + .collect::() + == s } } diff --git a/solution/2800-2899/2864.Maximum Odd Binary Number/Solution.rs b/solution/2800-2899/2864.Maximum Odd Binary Number/Solution.rs index b3d6521c7c75e..b0e6c7aaeac3b 100644 --- a/solution/2800-2899/2864.Maximum Odd Binary Number/Solution.rs +++ b/solution/2800-2899/2864.Maximum Odd Binary Number/Solution.rs @@ -1,9 +1,6 @@ impl Solution { pub fn maximum_odd_binary_number(s: String) -> String { - let cnt = s - .chars() - .filter(|&c| c == '1') - .count(); + let cnt = s.chars().filter(|&c| c == '1').count(); "1".repeat(cnt - 1) + &"0".repeat(s.len() - cnt) + "1" } } diff --git a/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/Solution.rs b/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/Solution.rs index 84c6385f2149d..66c780a2540ba 100644 --- a/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/Solution.rs +++ b/solution/2900-2999/2900.Longest Unequal Adjacent Groups Subsequence I/Solution.rs @@ -2,7 +2,7 @@ impl Solution { pub fn get_words_in_longest_subsequence( n: i32, words: Vec, - groups: Vec + groups: Vec, ) -> Vec { let mut ans = vec![]; diff --git a/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/Solution.rs b/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/Solution.rs index 1ed2888baa22a..774bb25bbbfae 100644 --- a/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/Solution.rs +++ b/solution/2900-2999/2901.Longest Unequal Adjacent Groups Subsequence II/Solution.rs @@ -2,15 +2,10 @@ impl Solution { pub fn get_words_in_longest_subsequence( n: i32, words: Vec, - groups: Vec + groups: Vec, ) -> Vec { fn check(s: &str, t: &str) -> bool { - s.len() == t.len() && - s - .chars() - .zip(t.chars()) - .filter(|(a, b)| a != b) - .count() == 1 + s.len() == t.len() && s.chars().zip(t.chars()).filter(|(a, b)| a != b).count() == 1 } let n = n as usize; diff --git a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/Solution.rs b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/Solution.rs index df5c77484cf77..b4c6180245343 100644 --- a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/Solution.rs +++ b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/Solution.rs @@ -6,9 +6,8 @@ impl Solution { for i in 0..n { for j in i + (k as usize)..=n { let t = &s[i..j]; - if - (t.matches('1').count() as i32) == k && - (ans.is_empty() || j - i < ans.len() || (j - i == ans.len() && t < &ans)) + if (t.matches('1').count() as i32) == k + && (ans.is_empty() || j - i < ans.len() || (j - i == ans.len() && t < &ans)) { ans = t.to_string(); } diff --git a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/Solution2.rs b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/Solution2.rs index d69f0aad21db3..20baca83e491e 100644 --- a/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/Solution2.rs +++ b/solution/2900-2999/2904.Shortest and Lexicographically Smallest Beautiful String/Solution2.rs @@ -21,9 +21,8 @@ impl Solution { j += 1; - if - cnt == k && - (ans.is_empty() || j - i < ans.len() || (j - i == ans.len() && &s[i..j] < &ans)) + if cnt == k + && (ans.is_empty() || j - i < ans.len() || (j - i == ans.len() && &s[i..j] < &ans)) { ans = s_chars[i..j].iter().collect(); } diff --git a/solution/2900-2999/2974.Minimum Number Game/Solution.rs b/solution/2900-2999/2974.Minimum Number Game/Solution.rs index fe93c8da6760f..e2a1471936b79 100644 --- a/solution/2900-2999/2974.Minimum Number Game/Solution.rs +++ b/solution/2900-2999/2974.Minimum Number Game/Solution.rs @@ -1,5 +1,5 @@ -use std::collections::BinaryHeap; use std::cmp::Reverse; +use std::collections::BinaryHeap; impl Solution { pub fn number_game(nums: Vec) -> Vec {