|
@@ -2,8 +2,8 @@ struct Solution;
|
|
|
|
|
|
impl Solution {
|
|
impl Solution {
|
|
pub fn can_complete_circuit(gas: Vec<i32>, cost: Vec<i32>) -> i32 {
|
|
pub fn can_complete_circuit(gas: Vec<i32>, cost: Vec<i32>) -> i32 {
|
|
- let mut gs = gas.iter().sum::<i32>();
|
|
|
|
- let mut cs = cost.iter().sum::<i32>();
|
|
|
|
|
|
+ let gs = gas.iter().sum::<i32>();
|
|
|
|
+ let cs = cost.iter().sum::<i32>();
|
|
|
|
|
|
if gs < cs {
|
|
if gs < cs {
|
|
return -1;
|
|
return -1;
|
|
@@ -88,7 +88,7 @@ mod tests {
|
|
fn test_can_complete_circuit1() {
|
|
fn test_can_complete_circuit1() {
|
|
let gas = vec![1,2,3,4,5];
|
|
let gas = vec![1,2,3,4,5];
|
|
let cost = vec![3,4,5,1,2];
|
|
let cost = vec![3,4,5,1,2];
|
|
- let res = Solution::can_complete_circuit(gas, cost);
|
|
|
|
|
|
+ let res = Solution::can_complete_circuit1(gas, cost);
|
|
assert_eq!(res, 3);
|
|
assert_eq!(res, 3);
|
|
}
|
|
}
|
|
}
|
|
}
|