pub struct Solution;
Expand description
Rust 的抽象层次很高,高级抽象,几乎零开销,函数式,高阶函数, Pattern Matching 这些语法让程序写起来会很简洁,同时也不失去性能。
主要是用 Iterator::fold()
的操作,不用栈,空间 O(1),
正反两次迭代,左右相等时记录最大的长度,反向也要执行一次。
字符串的 Chars
本身就是一个双端的迭代器,实现了 DoubleEndedIterator
这个 trait,
rev()
操作也是零开销。这里为了避免反向遍历的时候左右计数条件要换,
直接用一个 map()
把左右括号对换一下,所以计数的代码就可以直接复用了,
只要一套从左到右的逻辑。
Implementations§
Auto Trait Implementations§
impl Freeze for Solution
impl RefUnwindSafe for Solution
impl Send for Solution
impl Sync for Solution
impl Unpin for Solution
impl UnwindSafe for Solution
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more