add DP ver-2 solution, reduce space from O(n) to O(1)