Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
EFanZh committed May 21, 2024
1 parent f97dffa commit 77a1853
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/problem_0004_median_of_two_sorted_arrays/binary_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@ impl Solution {
let index = left;
let other = half - index;

let right_min = i32::min(
let right_min = f64::from(i32::min(
nums1.get(index).copied().unwrap_or(i32::MAX),
nums2.get(other).copied().unwrap_or(i32::MAX),
);
));

if total % 2 == 0 {
let left_max = i32::max(
let left_max = f64::from(i32::max(
nums1.get(index.wrapping_sub(1)).copied().unwrap_or(i32::MIN),
nums2.get(other.wrapping_sub(1)).copied().unwrap_or(i32::MIN),
);
));

(f64::from(left_max) + f64::from(right_min)) / 2.0
(left_max + right_min) / 2.0
} else {
f64::from(right_min)
right_min
}
}
}
Expand Down

0 comments on commit 77a1853

Please sign in to comment.