rewrite leetcode distinct sequences