LeetCode part 9 Dynamic Programming 1D