update second solution for longest-common-prefix