struct Solution{
}
impl Solution {
fn new() -> Self {
Solution{}
}
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param prices int整型一维数组
* @return int整型
*/
pub fn maxProfit(&self, prices: Vec<i32>) -> i32 {
let mut profit : i32 = 0;
let mut min_price : i32 = std::i32::MAX;
for (_,&price) in prices.iter().enumerate() {
profit = std::cmp::max(profit, price - min_price);
min_price = std::cmp::min(min_price, price);
}
return profit;
}
}

京公网安备 11010502036488号