Rust: 0ms - Single Expression Solutions
Using fold():\n\nimpl Solution {\n    pub fn largest_altitude(gain: Vec<i32>) -> i32 {\n        gain.into_iter()\n            .fold((0, 0), |(res, h), g| (res.m
**Using `fold()`**:\n```\nimpl Solution {\n    pub fn largest_altitude(gain: Vec<i32>) -> i32 {\n        gain.into_iter()\n            .fold((0, 0), |(res, h), g| (res.max(h + g), h + g))\n            .0\n    }\n}\n```\n---\n\n**Using `scan()`**:\n```\nimpl Solution {\n    pub fn largest_altitude(gain: Vec<i32>) -> i32 {\n        std::iter::once(0)\n            .chain(gain.into_iter())\n            .scan(0, |h, g| {\n                *h += g;\n                Some(*h)\n            })\n            .max()\n            .unwrap()\n    }\n}\n```\n---\n\nTime complexity: `O(n)`.\nExtra-space complexity: `O(1)`.\n
['Rust']