/**
* #[derive(PartialEq, Eq, Debug, Clone)]
* pub struct TreeNode {
* pub val: i32,
* pub left: Option<Box<TreeNode>>,
* pub right: Option<Box<TreeNode>>,
* }
*
* impl TreeNode {
* #[inline]
* fn new(val: i32) -> Self {
* TreeNode {
* val: val,
* left: None,
* right: None,
* }
* }
* }
*/
struct Solution{
}
impl Solution {
fn new() -> Self {
Solution{}
}
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param t1 TreeNode类
* @param t2 TreeNode类
* @return TreeNode类
*/
pub fn mergeTrees(&self, t1: Option<Box<TreeNode>>, t2: Option<Box<TreeNode>>) -> Option<Box<TreeNode>> {
if t1.is_none() {
return t2;
}
if t2.is_none() {
return t1;
}
let mut t1 = t1;
let mut t2 = t2;
t1.as_mut().unwrap().val += t2.as_mut().unwrap().val;
t1.as_mut().unwrap().left = Solution::mergeTrees(self, t1.as_mut().unwrap().left.take(), t2.as_mut().unwrap().left.take());
t1.as_mut().unwrap().right = Solution::mergeTrees(self, t1.as_mut().unwrap().right.take(), t2.as_mut().unwrap().right.take());
return t1;
}
}