Dynamic Programming Pattern Leetcode Solutions Java