Struct Solution

Source
pub struct Solution;
Expand description

Rust 的抽象层次很高,高级抽象,几乎零开销,函数式,高阶函数, Pattern Matching 这些语法让程序写起来会很简洁,同时也不失去性能。

主要是用 Iterator::fold() 的操作,不用栈,空间 O(1), 正反两次迭代,左右相等时记录最大的长度,反向也要执行一次。 字符串的 Chars 本身就是一个双端的迭代器,实现了 DoubleEndedIterator 这个 trait, rev() 操作也是零开销。这里为了避免反向遍历的时候左右计数条件要换, 直接用一个 map() 把左右括号对换一下,所以计数的代码就可以直接复用了, 只要一套从左到右的逻辑。

Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.