Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //package LeetCode;
- //
- ////编写一个函数来查找字符串数组中的最长公共前缀。
- ////如果不存在公共前缀,返回空字符串 ""。
- ////示例 1:
- ////输入: ["flower","flow","flight"]
- ////输出: "fl"
- ////示例 2:
- ////输入: ["dog","racecar","car"]
- ////输出: ""
- ////解释: 输入不存在公共前缀。
- ////说明:所有输入只包含小写字母 a-z 。
- //
- //public class A14LongestCommonPrefix {
- // public static void main(String[] args) {
- // String[] haha = {};
- // Solution solution = new Solution();
- // System.out.println(solution.longestCommonPrefix(haha));
- //
- // }
- //}
- //
- //class Solution {
- // public String longestCommonPrefix(String[] strs) {
- //// 定义存在的最长公共字符串的长度
- // int Max = 0;
- // if (strs.length == 0) {
- // return "";
- // }
- //// 定义输入的字符串数组中最短的字符串的长度,初始假设为1000
- // int minStr = 1000;
- // for (String string : strs) {
- // if (string.length() < minStr) {
- // minStr = string.length();
- // }
- // }
- //// 输入字符串数组的总字符串个数
- // int num = strs.length;
- // int i = 0;
- // LOOP:
- // for (; i < minStr; i++) {
- // for (int j = 0; j < num; j++) {
- // for (int k = j + 1; k < num; k++) {
- // if (strs[j].charAt(i) != strs[k].charAt(i)) {
- // break LOOP;
- // }
- // }
- // }
- // }
- // if (i == 0) {
- // return "";
- // } else {
- // return strs[0].substring(0, i);
- // }
- // }
- //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement