@@ -0,0 +1,1480 @@
+package main.algorithm.leetcode;%0A%0Aimport org.junit.Test;%0A%0A/**%0A * Title : main.algorithm.leetcode %3Cbr%3E%0A * Company : %E5%8C%97%E4%BA%AC%E5%8D%8E%E5%AE%87%E5%85%83%E5%85%B8%E4%BF%A1%E6%81%AF%E6%9C%8D%E5%8A%A1%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8 %3Cbr%3E%0A * Description :%0A *  %3Ca href=%22https://leetcode.com/problems/longest-common-prefix%22%3Eproblem%3C/a%3E%0A *%0A * @author chile%0A * @version 1.0%0A * @date 2019/4/28 13:13%0A */%0Apublic class LongestCommonPrefix %7B%0A%0A    class Solution %7B%0A        String longestCommonPrefix(String%5B%5D strs) %7B%0A            if (strs == null %7C%7C strs.length == 0) %7B%0A                return %22%22;%0A            %7D%0A%0A            if (strs.length %3C 2) %7B%0A                return strs%5B0%5D;%0A            %7D%0A%0A            String commonPrefix = getCommonPrefix(strs%5B0%5D, strs%5B1%5D);%0A            for (int i = 2; i %3C strs.length; i++) %7B%0A                commonPrefix = getCommonPrefix(strs%5Bi%5D, commonPrefix);%0A            %7D%0A%0A            return commonPrefix;%0A        %7D%0A%0A        String getCommonPrefix(String str1, String commonPrefix) %7B%0A            for (int i = 0; i %3C commonPrefix.length(); i++) %7B%0A                while (str1.indexOf(commonPrefix) != 0) %7B%0A                    commonPrefix = commonPrefix.substring(0, commonPrefix.length() - 1);%0A                %7D%0A            %7D%0A            return commonPrefix;%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void test1() %7B%0A        String%5B%5D strs = %7B %22flower%22, %22flow%22, %22flight%22 %7D;%0A        assert %22fl%22.equals(new Solution().longestCommonPrefix(strs));%0A    %7D%0A%0A    @Test%0A    public void test2() %7B%0A        assert new Solution().getCommonPrefix(%22flaaa%22, %22fleee%22).equals(%22fl%22);%0A    %7D%0A%7D%0A

longest common prefix