使用?运算符来对Option进行解包
This commit is contained in:
parent
4e23218ada
commit
94f76f5ffe
|
@ -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) })))
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue