leetcode #14 LongestCommenPrefix
来源:互联网 发布:淘宝金丝绒太极服 编辑:程序博客网 时间:2024/06/04 18:09
取到第一个单词,与第二个单词逐个单词比较,共同的就是prefix,然后再用它和第三个单词比较以此类推。
public class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length==0)return ""; if(strs[0]==null||strs[0].length()==0)return ""; String prefix = strs[0]; for(int i=1;i<strs.length;i++){ int j; for(j=0;j<Math.min(prefix.length(),strs[i].length());j++){ if(prefix.charAt(j)!=strs[i].charAt(j))break; } if(j>0)prefix=strs[i].substring(0, j); else if(j==0)return ""; } return prefix; }}
Fight On!
0 0
- leetcode #14 LongestCommenPrefix
- leetcode 14
- Leetcode(14)
- LeetCode(14)
- leetcode-14
- LeetCode (14) Plus One
- my leetcode#13 #14
- Leetcode #14 in cpp
- Leetcode no. 14
- leetCode练习(14)
- LeetCode 11-14
- 今日LeetCode--13 14
- leetcode 108(week 14)
- leetcode 14, 38, 345
- leetcode-14 commonPrefix
- LeetCode刷题(14)
- leetcode练习(14,7)
- 2017.11.14 LeetCode
- 安卓开发——JNI——回调java中的方法
- 抽象类和接口的区别
- C/C++语言内存对齐
- 在做自动化测试之前你需要知道的
- serialize a list of string and deserialize it
- leetcode #14 LongestCommenPrefix
- groovy 把json串转化成对象
- find maximized count of 0 on left and 1 on right in binary array
- Java线程中的ThreadPoolExecutor
- 利用jdk.tar.gz部署在CentOS/RedHat Enterprise Linux上
- Android屏幕关闭时开机CPU运行(以传感器为例)
- leetcode #1 TwoSum
- 冲动是魔鬼,冷静也是魔鬼(草稿)
- missing ranges of sorted integer array