fn extend_if_found_helper(
        root: &mut TreeNode,
        interval_end: usize,
        interval_len: usize,
    ) -> bool {
        if let Some(root) = root {
            let node_interval_end = root.interval_start + root.interval_len;
            match interval_end.cmp(&node_interval_end) {
                Ordering::Less => {
                    if Self::extend_if_found_helper(&mut root.left, interval_end, interval_len) {
                        root.update_max_len();
                        return true;
                    }
                }
                Ordering::Greater => {
                    if Self::extend_if_found_helper(&mut root.right, interval_end, interval_len) {
                        root.update_max_len();
                        return true;
                    }
                }
                Ordering::Equal => {
                    root.interval_len += interval_len;
                    root.update_max_len();
                    return true;
                }
            }
        }

        false
    }
/// Helper to extend interval in tree. Returns true on found and updates it, false otherwise.
Helper to extend interval in tree. Returns true on found and updates it, false otherwise.
Helper to extend interval in tree . Returns true on found and updates it false otherwise .
fn extend_if_found_helper(
        root: &mut TreeNode,
        interval_end: usize,
        interval_len: usize,
    ) -> bool {
        if let Some(root) = root {
            let node_interval_end = root.interval_start + root.interval_len;
            match interval_end.cmp(&node_interval_end) {
                Ordering::Less => {
                    if Self::extend_if_found_helper(&mut root.left, interval_end, interval_len) {
                        root.update_max_len();
                        return true;
                    }
                }
                Ordering::Greater => {
                    if Self::extend_if_found_helper(&mut root.right, interval_end, interval_len) {
                        root.update_max_len();
                        return true;
                    }
                }
                Ordering::Equal => {
                    root.interval_len += interval_len;
                    root.update_max_len();
                    return true;
                }
            }
        }
        false
    }
fn extend_if_found_helper ( root : & mut TreeNode , interval_end : usize , interval_len : usize , ) -> bool { if let Some ( root ) = root { let node_interval_end = root . interval_start + root . interval_len ; match interval_end . cmp ( & node_interval_end ) { Ordering :: Less => { if Self :: extend_if_found_helper ( & mut root . left , interval_end , interval_len ) { root . update_max_len ( ) ; return true ; } } Ordering :: Greater => { if Self :: extend_if_found_helper ( & mut root . right , interval_end , interval_len ) { root . update_max_len ( ) ; return true ; } } Ordering :: Equal => { root . interval_len += interval_len ; root . update_max_len ( ) ; return true ; } } } false }
Helper to extend interval in tree.
Helper to extend interval in tree .
root
&mut TreeNode
interval_end
usize
interval_len
usize
root
&mut TreeNode
interval_end
usize
interval_len
usize