Advertisement
Guest User

Untitled

a guest
May 27th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. //package LeetCode;
  2. //
  3. ////编写一个函数来查找字符串数组中的最长公共前缀。
  4. ////如果不存在公共前缀,返回空字符串 ""。
  5. ////示例 1:
  6. ////输入: ["flower","flow","flight"]
  7. ////输出: "fl"
  8. ////示例 2:
  9. ////输入: ["dog","racecar","car"]
  10. ////输出: ""
  11. ////解释: 输入不存在公共前缀。
  12. ////说明:所有输入只包含小写字母 a-z 。
  13. //
  14. //public class A14LongestCommonPrefix {
  15. // public static void main(String[] args) {
  16. // String[] haha = {};
  17. // Solution solution = new Solution();
  18. // System.out.println(solution.longestCommonPrefix(haha));
  19. //
  20. // }
  21. //}
  22. //
  23. //class Solution {
  24. // public String longestCommonPrefix(String[] strs) {
  25. //// 定义存在的最长公共字符串的长度
  26. // int Max = 0;
  27. // if (strs.length == 0) {
  28. // return "";
  29. // }
  30. //// 定义输入的字符串数组中最短的字符串的长度,初始假设为1000
  31. // int minStr = 1000;
  32. // for (String string : strs) {
  33. // if (string.length() < minStr) {
  34. // minStr = string.length();
  35. // }
  36. // }
  37. //// 输入字符串数组的总字符串个数
  38. // int num = strs.length;
  39. // int i = 0;
  40. // LOOP:
  41. // for (; i < minStr; i++) {
  42. // for (int j = 0; j < num; j++) {
  43. // for (int k = j + 1; k < num; k++) {
  44. // if (strs[j].charAt(i) != strs[k].charAt(i)) {
  45. // break LOOP;
  46. // }
  47. // }
  48. // }
  49. // }
  50. // if (i == 0) {
  51. // return "";
  52. // } else {
  53. // return strs[0].substring(0, i);
  54. // }
  55. // }
  56. //}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement