solve the Longest Common Prefix