@@ -0,0 +1,2289 @@
+/*%0ASolution 3:%0Abinary search%0A*/%0Apublic class Solution %7B%0A    public String longestCommonPrefix(String%5B%5D strs) %7B%0A        if(strs.length %3C 1)%0A            return %22%22;%0A        %0A        int minLen = strs%5B0%5D.length();%0A        for(int i = 1; i %3C strs.length; i++)%0A            minLen = Math.min(minLen, strs%5Bi%5D.length());%0A        %0A        int left = 0, right = minLen - 1;%0A        while(left %3C= right) %7B%0A            int middle = (left + right) / 2;%0A            if(isCommonPrefix(strs, middle)) %7B%0A                left = middle + 1;%0A            %7D%0A            else %7B%0A                right = middle - 1;%0A            %7D%0A        %7D%0A        return strs%5B0%5D.substring(0, (left + right + 1) / 2);%0A    %7D%0A    %0A    private boolean isCommonPrefix(String%5B%5D strs, int len) %7B%0A        String prefix = strs%5B0%5D.substring(0, len + 1);%0A        for(int i = 1; i %3C strs.length; i++) %7B%0A            if(strs%5Bi%5D.indexOf(prefix) != 0)%0A                return false;%0A        %7D%0A        return true;%0A    %7D%0A%7D%0A%0A/*%0ASolution 2:%0A*/%0Apublic class Solution %7B%0A    public String longestCommonPrefix(String%5B%5D strs) %7B%0A        if(strs.length %3C 1)%0A            return %22%22;%0A        %0A        String prefix = strs%5B0%5D;%0A        for(int i = 1; i %3C strs.length; i++) %7B%0A            while(strs%5Bi%5D.indexOf(prefix) != 0) %7B%0A                prefix = prefix.substring(0, prefix.length() - 1);%0A                if(prefix.isEmpty())%0A                    return %22%22;%0A            %7D%0A        %7D%0A        return prefix;%0A    %7D%0A%7D%0A%0A/*%0ASolution 1: %E5%8F%AA%E6%83%B3%E8%91%97%E7%9B%B4%E7%B7%9A%E9%80%B2%E6%94%BB%E7%9A%84%E7%AC%A8%E6%96%B9%E6%B3%95%0AComplexity high%0A*/%0Apublic class Solution %7B%0A    public String longestCommonPrefix(String%5B%5D strs) %7B%0A        if(strs.length %3C 1 %7C%7C strs%5B0%5D.length() %3C 1)%0A            return %22%22;%0A        %0A        int minLen = strs%5B0%5D.length();%0A        for(int i = 0; i %3C strs.length; i++) %7B%0A            minLen = Math.min(minLen, strs%5Bi%5D.length());%0A        %7D%0A        %0A        StringBuilder sb = new StringBuilder();%0A        int idx = 0;%0A        for(int i = 0; i %3C strs%5B0%5D.length() && i %3C minLen; i++) %7B%0A            char c = strs%5B0%5D.charAt(idx);%0A            for(int j = 0; j %3C strs.length; j++) %7B%0A                if(c != strs%5Bj%5D.charAt(idx))%0A                    return sb.toString();%0A                else if(j == strs.length - 1)%0A                    sb.append(c);%0A            %7D%0A            idx++;%0A        %7D%0A        return sb.toString();%0A    %7D%0A%7D%0A

Create LongestCommonPrefix.java