Fix cache, recursion and test.

    Use instance cache: https://oj.leetcode.com/faq/
    Recursion: minimum cannot below zero.
    Fix test case and use unittest.