Leetcode || Longest Common Prefix
来源:互联网 发布:讨厌知乎 编辑:程序博客网 时间:2024/05/21 04:24
Write a function to find the longest common prefix string amongst an array of strings.
Subscribe to see which companies asked this question
class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length == 0) return ""; if(strs.length == 1) return strs[0]; int min_len = strs[0].length(); for(String str : strs) { if(str == "") return ""; if(str.length()<min_len) min_len = str.length(); } int k = 0; String result = ""; boolean same = true; for(int i=0; i<min_len && same; i++) { for(int j=0; j<strs.length-1; j++) { if(strs[j].charAt(i) != strs[j+1].charAt(i)) { same = false; break; } } if(same) result += strs[0].charAt(i); } return result; }}
0 0
- LeetCode: Longest Common Prefix
- LeetCode Longest Common Prefix
- LeetCode : Longest Common Prefix
- [Leetcode] Longest Common Prefix
- [LeetCode] Longest Common Prefix
- [LeetCode]Longest Common Prefix
- LeetCode-Longest Common Prefix
- [LeetCode] Longest Common Prefix
- LeetCode - Longest Common Prefix
- leetcode Longest Common Prefix
- LeetCode | Longest Common Prefix
- Leetcode: Longest Common Prefix
- LeetCode: Longest Common Prefix
- 【LeetCode】Longest Common Prefix
- [LeetCode] Longest Common Prefix
- [LeetCode]Longest Common Prefix
- leetcode: Longest Common Prefix
- LeetCode Longest Common Prefix
- 二叉树模板
- Hibernate 的对象状态
- java读取TXT文件的方法
- 使用xUtils下载和上传文件
- 登陆界面模拟03-sign_up界面
- Leetcode || Longest Common Prefix
- 赫夫曼树
- 牛客网 | 求1+2+3+...+n
- Codeforces Round #312 (Div. 2) E A Simple Task 线段树
- python抓取网页内容
- java.lang.UnsupportedClassVersionError: t : Unsupported major.minor version
- 该 App 的 Info.plist 不能包含阻碍在任何 iOS 设备上打开此 App 的 UIRequiredDeviceCapabilities 键值
- Android ORM数据库框架之-greenDao(三)
- 寄存器某一位置位或者清零