Finish leetcode_516.