tag:blogger.com,1999:blog-8522573717713847738.post4470321293296050631..comments2024-03-28T00:14:29.070-07:00Comments on Yu's Coding Garden : leetcode Question 43: Longest Common PrefixAnonymoushttp://www.blogger.com/profile/00263085222060621782noreply@blogger.comBlogger3125tag:blogger.com,1999:blog-8522573717713847738.post-45705480989048756832014-11-17T19:14:29.281-08:002014-11-17T19:14:29.281-08:00I would first sort the strings in alphabetical ord...I would first sort the strings in alphabetical order. And only compare the first and last strings. Use bisection to accelerateAnonymoushttps://www.blogger.com/profile/15407279245400852685noreply@blogger.comtag:blogger.com,1999:blog-8522573717713847738.post-21370703793148858942014-06-30T07:35:11.716-07:002014-06-30T07:35:11.716-07:00Yes, it is a good suggestion ! I have modified t...Yes, it is a good suggestion ! I have modified the code (also add the python version).<br />Thanks !Anonymoushttps://www.blogger.com/profile/00263085222060621782noreply@blogger.comtag:blogger.com,1999:blog-8522573717713847738.post-45283630579610428352014-06-28T13:30:03.439-07:002014-06-28T13:30:03.439-07:00You don't require that extra boolean variable ...You don't require that extra boolean variable (f1) , if the condition (strs[j][i]!=str[i]) becomes true, you can just return str.substr(0, i) from there only. Otherwise, when the loop terminates without then at the end, you can just return the whole string str;Anonymoushttps://www.blogger.com/profile/10037853302088801249noreply@blogger.com