Finish leetcode_5112.