Redian新闻
>
搞了小半个月,leetcode还有20题
avatar
搞了小半个月,leetcode还有20题# JobHunting - 待字闺中
h*y
1
全部用爪哇写的,第一遍, 先做的题都有点忘了。。。><
avatar
a*x
2
我都一个多月了还有50道呢。zz
avatar
f*t
3
java有些题怎么都ac不了,比如wildcard matching和common prefix。谁有能ac的代码
希望贡献出来膜拜一下
avatar
h*y
4
ac是啥?

【在 f*******t 的大作中提到】
: java有些题怎么都ac不了,比如wildcard matching和common prefix。谁有能ac的代码
: 希望贡献出来膜拜一下

avatar
d*n
5
同问

【在 h**********y 的大作中提到】
: ac是啥?
avatar
c*r
6
一共一百二十多题,半小时高了100道?不是大牛的BSO就是坑 ;)
avatar
c*t
7
牛,15天做100多道题,一天7道啊

【在 h**********y 的大作中提到】
: 全部用爪哇写的,第一遍, 先做的题都有点忘了。。。><
avatar
c*s
8
accepted

【在 h**********y 的大作中提到】
: ac是啥?
avatar
f*t
9
楼上回答过了,你快发代码呀

【在 h**********y 的大作中提到】
: ac是啥?
avatar
l*a
10
里面很多题很基本常见吧
另外过去的两周大多在放假

【在 c********t 的大作中提到】
: 牛,15天做100多道题,一天7道啊
avatar
d*g
11

我写的这个common prefix 有时候大测试会超时,有时候能过~
public String longestCommonPrefix(String[] strs)
{
String result = "";
if(strs.length == 0) return result;

int smallestLength = Integer.MAX_VALUE;
for(String str : strs)
{
if(str.isEmpty()) return result;
smallestLength = Math.min(smallestLength, str.length());
}

for(int i = 0; i < smallestLength; ++i)
{
if(!isCommonLetter(strs, i)) return result;
result += strs[0].charAt(i);
}
return result;
}
private boolean isCommonLetter(String[] strs, int i)
{
char letter = strs[0].charAt(i);
for(String str : strs)
if(letter != str.charAt(i)) return false;
return true;
}

【在 f*******t 的大作中提到】
: java有些题怎么都ac不了,比如wildcard matching和common prefix。谁有能ac的代码
: 希望贡献出来膜拜一下

avatar
c*a
12
新鲜写的 longest common prefix,之前没做过
public class Solution {
public String longestCommonPrefix(String[] strs) {
// Start typing your Java solution below
// DO NOT write main() function
if(strs.length ==0) return "";
String shortest=strs[0];
for(String s: strs){
if(s.isEmpty()) return "";
if(s.length()shortest = s;
}
int length = shortest.length();
while(true){
boolean good=true;
for(String s: strs){
if(!s.substring(0,length).equals(shortest.substring(0,length
))){
length--;
good = false;
}
}
if(good)
return shortest.substring(0,length);
if(length==0) return "";
}
}
}
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。