From 5ea26cee9b75ff472dfa6597a9f1c64dbe4f7e0dd0dadec5cbc0f8c438ede903 Mon Sep 17 00:00:00 2001 From: Mars Ultor Date: Fri, 18 Apr 2025 13:36:49 -0500 Subject: [PATCH] more readable --- README.md | 5 ++--- src/main.rs | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 41864b0..b35c18e 100644 --- a/README.md +++ b/README.md @@ -64,12 +64,11 @@ fn find_min(cache: &mut HashMap, target_sum: u64, coins: &Vec) -> if running_min != u64::MAX { cache.insert(target_sum, running_min); - Some(running_min) + return Some(running_min); } else { cache.insert(target_sum, u64::MAX); // Mark as unreachable - None + return None; } -} ``` Essentially, the purpose of the above code is to traverse a tree of possible coin decisions. As long as the coin denomination is smaller than the target, it's possible to recursively iterate through all combinations of coins while both caching and checking for a base case. This behavior is called memorization. The base case for any branch of the tree is when the target sum is equivalent to the coin of interest. diff --git a/src/main.rs b/src/main.rs index 3a3512c..7b88c7e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -42,10 +42,10 @@ fn find_min(cache: &mut HashMap, target_sum: u64, coins: &Vec) -> if running_min != u64::MAX { cache.insert(target_sum, running_min); - Some(running_min) + return Some(running_min); } else { cache.insert(target_sum, u64::MAX); // Mark as unreachable - None + return None; } }