[LeetCode] 1531. String Compression II
I thought it should be Greedy at first, but was stuck in Example 2. Then, I considered about DP, but found it hard to figure out how to build the larger solution from the sub-problem.
So, another time I reached out for solution.
We use dp[i][j] to represent the minimum length of the first i letters after compression and after j deletions.
It obvious that if we delete the i-th letter, and then dp[i][j] = dp[i-1][j-1].
If we don’t, we can scan the former string sequence to try to “combine” the letters.
![[LeetCode] 1531. String Compression II](/blog/images/34/cover.png)
![[LeetCode] 4. Median of Two Sorted Arrays](/blog/images/33/cover.png)
![[Review] Assisting Static Analysis with Large Language Models: A ChatGPT Experiment](/blog/images/42/cover.png)
![[Review] Detecting Missed Security Operations Through Differential Checking of Object-based Similar Paths](/blog/images/41/cover.png)
![[Review] GPTScan: Detecting Logic Vulnerabilities in Smart Contracts by Combining GPT with Program Analysis](/blog/images/40/cover.png)
![[Review] MoonShine: Optimizing OS Fuzzer Seed Selection with Trace Distillation](/blog/images/39/cover.png)
![[Review] One Simple API Can Cause Hundreds of Bugs: An Analysis of Refcounting Bugs in All Modern Linux Kernels](/blog/images/38/cover.png)