Skip to content

Commit

Permalink
perf(linkedlist: change a mut into inmut) (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
donjuanplatinum authored Aug 6, 2024
1 parent 0565af5 commit b692de2
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/structure/linkedlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ impl<T, const N: usize> From<[T; N]> for LinkedList<T> {
/// ```
pub fn add_two_linkedlist(a: LinkedList<i32>, b: LinkedList<i32>) -> LinkedList<i32> {
let mut result = LinkedList::new();
let mut current = &mut result;
let current = &mut result;
let (mut p1, mut p2) = (a, b);
let mut sum = 0i32;
while p1.front().is_some() || p2.front().is_some() || sum != 0 {
Expand All @@ -468,7 +468,6 @@ pub fn add_two_linkedlist(a: LinkedList<i32>, b: LinkedList<i32>) -> LinkedList<
pub fn add_two_binary_linkedlist(a: LinkedList<bool>, b: LinkedList<bool>) -> LinkedList<bool> {
let mut result = LinkedList::new();
let (mut p1, mut p2) = (a, b);
let mut carry = false;
// sum[0]为第一个链表的值 sum[1]为第二个链表的值 sum[2]为上次进位
let mut sum = [false; 3];
while p1.front().is_some() || p2.front().is_some() || sum[2] == true {
Expand Down

0 comments on commit b692de2

Please sign in to comment.