rewrite leetcode longest common prefix