Rust Day 14: Leetcode — Path Sum
Exams are nearing! Time is running out. Will take a pause on the blogging side of things. I ponder how society works. Many a time, we do “Work” which probably is not in our interest to feed ourselves. We have a side hustle going, but then, work is there filling a large part of your life. No wonder the 80/20 rule was discovered.
The 80/20 productivity rule is one of them. It clearly states that 80% of your results come from 20% of your efforts.
Anyways, let's dive into today's problem.
Problem:
Logic:
Use recursion to check: if you are null, if you are a leaf, or try exploring the children.
Code:
Syntax:
if let Some(new_var_name) = root {
This was a nice syntax instead of using the verbose match.- curr_node.left.
is_none()
is another function that directly checks for null condition, rather thanmatch
.
Reference:
Found it Interesting?
Please show your support by 👏