【LeetCode】14.Longest Common Prefix(Easy)解题报告
来源:互联网 发布:淘宝男装模特红人 编辑:程序博客网 时间:2024/06/06 05:43
【LeetCode】14.Longest Common Prefix(Easy)解题报告
tags:String
题目地址:https://leetcode.com/problems/longest-common-prefix/description/
题目描述:
Write a function to find the longest common prefix string amongst an array of strings.
找出字符串序列中重复的字符串。提交了好几次,因为越界问题,要提前取到最小长度就可以了。还有不要忘异常判断。
Solutions:
class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length==0){ return ""; } int len=strs[0].length(); for(int i=0;i<strs.length;i++){ len=Math.min(strs[i].length(),len); } for(int i=0;i<strs.length-1;i++){ for(int j=0;j<len;j++){ if(strs[i].charAt(j)!=strs[i+1].charAt(j)){ len=j; } } } return strs[0].substring(0,len); }}
Date:2017年12月19日
阅读全文
0 0
- 【LeetCode】14.Longest Common Prefix(Easy)解题报告
- [leetcode] 14. Longest Common Prefix 解题报告
- [Leetcode] 14. Longest Common Prefix 解题报告
- leetcode解题报告14. Longest Common Prefix
- LeetCode解题报告--Longest Common Prefix
- [LeetCode] Longest Common Prefix 解题报告
- [LeetCode] Longest Common Prefix 解题报告
- [LeetCode 解题报告]014. Longest Common Prefix
- 【LeetCode】Longest Common Prefix 解题报告
- Leetcode Longest Common Prefix 解题报告
- Leetcode 14. Longest Common Prefix (Easy) (cpp)
- LeetCode 14. Longest Common Prefix (easy)
- Longest Common Prefix解题报告
- Leetcode[Easy] - Longest Common Prefix
- 14. Longest Common Prefix Easy
- Longest Common Prefix ——解题报告
- 14.LeetCode Longest Common Prefix(easy)[字符串公共前缀]
- Leetcode 14.Longest Common Prefix——python (easy)
- AngularJS中如何使用$parse或$eval在运行时对Scope变量赋值
- 在Eclipse下,出现“找不到或无法加载主类 ”的问题的解决方式
- Notepad++ v7.5.1 制表符的设置
- [喵咪大数据]Hadoop节点添加下线和磁盘扩容操作
- 下载方法,移动端或者浏览器均可
- 【LeetCode】14.Longest Common Prefix(Easy)解题报告
- freemarker---大数字自动加逗号分隔&更大数字认为是字符串不用逗号分隔
- codevs 1743 反转卡片【Splay区间翻转】
- 个人静态网页的实现
- win7下IIS的安装和配置 图文教程
- 每天一个linux命令(2):cd命令
- 在angualr4中年引入ng-bootstrap
- Unhandled exception at 0x747E08B2 in evss.exe: Microsoft C++ exception: xsd:
- 关于innodb中MVCC的一些理解