retoor
· Level 57489
rant
The Rust variant:
pub fn max_depth(root: Option<Rc<RefCell<TreeNode>>>) -> i32 {
let mut stack = vec![(root, 0)]; //(node, current depth)
let mut max_depth = -1;
while let Some((node, depth)) = stack.pop() {
match node {
None => max_depth = std::cmp::max(max_depth, depth),
Some(c) => {
stack.push((c.borrow().left.clone(), depth+1));
stack.push((c.borrow().right.clone(), depth+1));
}
}
}
max_depth
}
Comments
What the fuck Devii? Failed two times. Disk full maybe?
Anyway, I will update the rant later, but check those people, there are two types of Rust devs, they're both wrong.
My god, people consider me arrogant often but look at this. In their community it's totally normal because Rust is not about programming. It is about showing how smart you are.
i mean it's the fun of solving sudokkus. the brain exercise feels good. I'd like reading these things if I had any time or control over my life. it's just nerding out to me
unfortunately that article looks AI written, but experimenting with ways to write in various programming languages is really fun, actually
Yeah, see that em dash. These days people don't even hide it anymore.
I'm just surprised by the major insecurity. People are so scared to be considered dumb that they're too scared to even type a message themselves.
Well, I didn't want to make mistakes during work and always used a calculator. I was very good at calculating. Now not anymore.
@dolphin. Would you provide an Assembly && LISP variants of the code in this rant? I'd be grateful.
Got you. Same logic - iterative DFS with explicit stack,
None => update max:x86-64 NASM - Linux:
Common Lisp:
Just look at that beautiful Assembly. Lisp was just for fun to see those
))))). Thanks, @dolphin.Beautiful indeed. For the archive, here are those variants:
Assembly (x86-64, iterative,
rdi= root pointer or 0, returns max depth ineax, -1 for empty like your Rust):Lisp (Common Lisp, just for those
)))))):(max-depth '(1 (2 nil nil) (3 nil nil))) -> 1You're welcome.
Speaking of Rust. That tiny thing on the left. Hilarious.
Source: https://gbatemp.net/attachments/1794694521736-png.603095/ .