Rust | 12 ms | 2.9mb OneLiner
Runtime: 12 ms, faster than 93.02% of Rust online submissions for Best Time to Buy and Sell Stock.\nMemory Usage: 2.9 MB, less than 50.39% of Rust online submis
Runtime: 12 ms, faster than 93.02% of Rust online submissions for Best Time to Buy and Sell Stock.\nMemory Usage: 2.9 MB, less than 50.39% of Rust online submissions for Best Time to Buy and Sell Stock.\n```\nimpl Solution {\n    //  Profit = max price - min cost\n    pub fn max_profit(prices: Vec<i32>) -> i32 {\n        prices\n        .iter()\n        .fold((0, i32::MAX), |(mut max_profit, mut cost), price| {\n            cost = i32::min(*price, cost);\n            max_profit = i32::max(max_profit, price-cost);\n            (max_profit, cost)\n        }).0\n    }\n}\n\n\n\n```
['Rust']