LeetCode 14. Longest Common Prefix 找字符串数组最长相同前缀
2017-04-19 14:49
459 查看
题目:
Write a function to find the longest common prefix string amongst an array of strings.
Subscribe to see which companies asked this question.
Write a function to find the longest common prefix string amongst an array of strings.
Subscribe to see which companies asked this question.
public class Solution { public String longestCommonPrefix(String[] strs) { if(strs==null||strs.length==0) return ""; String result = strs[0]; int i=1; while(i<strs.length){ while(!strs[i].startsWith(result)){ result = result.substring(0, result.length()-1); } i++; } return result; } }
相关文章推荐
- Longest Common Prefix 字符串数组中查找最长相同前缀字符串@LeetCode
- LeetCode 14. Longest Common Prefix--字符串数组元素的最长公共前缀
- leetcode-14. Longest Common Prefix(寻找字符串数组最长公共前缀)
- LeetCode -- 求字符串数组中的最长公共前缀
- LeetCode -- 求字符串数组中的最长公共前缀
- leetcode:Longest Common Prefix(取最长字符串前缀)
- LeetCode 找到一个字符串数组的最长公共前缀
- Leetcode#14. Longest Common Prefix (最长公共前缀字符串)
- leetcode-14-求字符串数组最长公共前缀
- leetcode:java.T014_LongestCommonPrefix--写一个函数找出一个字串所数组中的最长的公共前缀
- [转][LeetCode]Longest Common Prefix ——求字符串的最长公共前缀
- Lettcode_14_Longest Common Prefix——查找字符串数组中最长公共前缀字符串
- 每日一练之Longest Common Prefix【LeetCode No.14】——求字符串的最长公共前缀
- longest-common-prefix 求字符串数组的最长公共前缀
- leetcode 14. Longest Common Prefix-最长前缀|字符串
- leetcode_14. Longest Common Prefix 求字符串数组中所有字符串的最长前缀
- 【LeetCode-面试算法经典-Java实现】【014-Longest Common Prefix(最长公共前缀)】
- [leetcode] Longest Common Prefix 字符窜最长公共前缀判断
- [LeetCode] Longest Common Prefix 最长共同前缀
- LeetCode 14 Longest Common Prefix(最长公共前缀)(String)