[leetcode]Optimize 117's logic