leetcode scramble string - dp - refactoring