From c10e7bf42f8f117173e02e3799b1cc6727f1ff98 Mon Sep 17 00:00:00 2001 From: yennanliu Date: Sun, 8 Dec 2024 17:44:46 +0800 Subject: [PATCH] update cheatsheet, progress --- data/progress.txt | 2 +- doc/cheatsheet/hash_map.md | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/data/progress.txt b/data/progress.txt index eb66763c..ab8e2fbc 100644 --- a/data/progress.txt +++ b/data/progress.txt @@ -1,4 +1,4 @@ -20241208: 304,853,325 +20241208: 304,853,325,560(todo) 20241202: 370(todo),1109(todo) 20241130: 34,767 20241126: 722,380 diff --git a/doc/cheatsheet/hash_map.md b/doc/cheatsheet/hash_map.md index 63e55f16..21eb1c57 100644 --- a/doc/cheatsheet/hash_map.md +++ b/doc/cheatsheet/hash_map.md @@ -44,6 +44,17 @@ - `TODO : note this as pattern!!!` - LC 325: Maximum Size Subarray Sum Equals k - `prefix sum` + hashmap + ``` + subarray[i,j] = prefixSum[j] - prefixSum[i-1] + + so, to find a subarray equals k + + -> prefixSum[j] - prefixSum[i-1] = k + + -> prefixSum[j] - k = prefixSum[i-1] + + -> so all need to do is : check if "prefixSum[j] - k" is in map + ``` - Any problems with below: - need to cache - avoid double loop