File tree Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Expand file tree Collapse file tree 1 file changed +4
-4
lines changed Original file line number Diff line number Diff line change @@ -34,15 +34,15 @@ impl Solution {
3434 pub fn has_path_sum ( root : Option < Rc < RefCell < TreeNode > > > , sum : i32 ) -> bool {
3535 if root. is_none ( ) { return false }
3636 let mut deq = VecDeque :: new ( ) ;
37- deq. push_back ( ( 0 , root. clone ( ) ) ) ;
37+ deq. push_back ( ( 0 , root. unwrap ( ) . clone ( ) ) ) ;
3838 while !deq. is_empty ( ) {
39- if let Some ( ( acc, Some ( node) ) ) = deq. pop_front ( ) {
39+ if let Some ( ( acc, node) ) = deq. pop_front ( ) {
4040 let acc = acc + node. borrow ( ) . val ;
4141 if node. borrow ( ) . left . is_none ( ) && node. borrow ( ) . right . is_none ( ) {
4242 if acc == sum { return true }
4343 } else {
44- deq. push_back ( ( acc, node. borrow ( ) . left . clone ( ) ) ) ;
45- deq. push_back ( ( acc, node. borrow ( ) . right . clone ( ) ) ) ;
44+ if node . borrow ( ) . left . is_some ( ) { deq. push_back ( ( acc, node. borrow ( ) . left . as_ref ( ) . unwrap ( ) . clone ( ) ) ) } ;
45+ if node . borrow ( ) . right . is_some ( ) { deq. push_back ( ( acc, node. borrow ( ) . right . as_ref ( ) . unwrap ( ) . clone ( ) ) ) } ;
4646 }
4747 }
4848 }
You can’t perform that action at this time.
0 commit comments