diff --git a/problems/0112.路径总和.md b/problems/0112.路径总和.md index d50f23f9..482787bf 100644 --- a/problems/0112.路径总和.md +++ b/problems/0112.路径总和.md @@ -1213,6 +1213,28 @@ object Solution { } ``` +## rust + +### 112.路径总和.md + +```rust +use std::rc::Rc; +use std::cell::RefCell; +impl Solution { + pub fn has_path_sum(root: Option>>, target_sum: i32) -> bool { + if root.is_none() { + return false; + } + let node = root.unwrap(); + if node.borrow().left.is_none() && node.borrow().right.is_none() { + return node.borrow().val == target_sum; + } + return Self::has_path_sum(node.borrow().left.clone(), target_sum - node.borrow().val) + || Self::has_path_sum(node.borrow().right.clone(), target_sum - node.borrow().val); + } +} +``` +