LeetCode
来源:互联网 发布:阿里云 404 编辑:程序博客网 时间:2024/06/09 18:56
Longest Common Prefix
Total Accepted: 2025 Total Submissions: 7610My SubmissionsWrite a function to find the longest common prefix string amongst an array of strings.
这道题很简单,其实最重要的是边界条件,一定要思维缜密,写代码要尽力达到从上到下一次写完而不会出现边界问题的地步!
public class Solution { public String longestCommonPrefix(String[] strs){ if(strs.length==0) return ""; int index=0; while(true){ if(strs[0].equals("")) return ""; if(index>=strs[0].length()) break; char c=strs[0].charAt(index); int i=0; for(i=0;i<strs.length;i++){ if(index>=strs[i].length()) break; if(strs[i].charAt(index)!=c) break; } if(i<strs.length) break; index++; } return strs[0].substring(0,index);}}
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode
- leetcode:
- leetcode:
- LeetCode
- leetcode
- LEETCODE
- leetcode
- leetCode
- leetcode
- [leetcode]
- LeetCode
- leetcode
- leetcode:
- leetcode
- hdu 2680 Choose the best route
- NYOJ-67-三角形面积-2013年08月21日09:15:13
- hdu 4429 Split the Rectangle
- IOS 四种保存数据的方式
- 必须知道的HTML5十件事
- LeetCode
- openfire使用自定义用户表
- kvo和kvc
- 第11周项目6-*#图
- NYOJ-655-光棍的yy-2013年08月21日16:50:16
- oracle中的游标学习
- eclipse安装插件
- 更新证书错误Code Sign error: Provisioning profile ‘XXXX'can't be found
- ENC28J60学习笔记——第3部分