使用?运算符来对Option进行解包

This commit is contained in:
游由 2021-11-16 17:42:09 +08:00
parent 4e23218ada
commit 94f76f5ffe
2 changed files with 2 additions and 4 deletions

View File

@ -64,7 +64,7 @@ impl Codec {
}
fn deserialize_sub(&self, map: &mut Map<Chunks<u8>, fn(&[u8]) -> i32>) -> Option<Rc<RefCell<TreeNode>>> {
match map.next().unwrap() {
match map.next()? {
i32::MAX => None,
val => Some(Rc::new(RefCell::new(TreeNode { val, left: self.deserialize_sub(map), right: self.deserialize_sub(map) })))
}

View File

@ -1,7 +1,5 @@
use crate::Solution;
use crate::structure::ListNode;
use std::option::Option::Some;
use std::ptr::null;
impl Solution {
@ -38,7 +36,7 @@ impl Solution {
let mut prev = None;
let mut curr = head;
while curr.is_some() {
let mut node = curr.take().unwrap();
let mut node = curr.take()?;
curr = node.next.take();
node.next = prev;
prev = Some(node);