这题写凌晨2、3点,本来要用c的,最後用JAVA,然後睡觉前送出去Time Limit Exceeded,心都要碎了,好家在把print拿掉後就过了,可喜可贺?
题号3 标题:Longest Substring Without Repeating Characters 难度:Medium
Given a string s, find the length of the longest substring without repeating characters.
我的程序码
class Solution {
public int lengthOfLongestSubstring(String s) {
ArrayList<String> temp = new ArrayList<String>();
int i=0,j=0,count=1,result=1;
if(s.isEmpty()){
return 0;
}
temp.add(Character.toString(s.charAt(0)));
for(i=1;i<s.length();i++){
String dtemps = Character.toString(s.charAt(i));
if(temp.contains(dtemps)){
//System.out.println(temp.indexOf(Character.toString(s.charAt(i))));
int dtemp = temp.indexOf(dtemps);
if(result<count){
result=count;
}
for(j=0;j<=dtemp;j++){
temp.remove(0);
}
if(temp.size()!=0){
count=temp.size();
}else{
count = 0;
}
}
temp.add(dtemps);
count++;
// for(j=0;j<temp.size();j++){
// System.out.print(temp.get(j));
// }
// System.out.print(" count:"+count);
System.out.println();
}
if(count>result){
result = count;
}
return result;
}
}
DAY20心得
终於走完1/3了,加油加油,来去倒垃圾
>>: Day 20: SOLID 设计原则 — ISP (待改进中... )
今天来看一下如何使用Shioaji问回历史交易资料,不过在此先提醒一下,上一篇有讲到的永丰讲师的Yo...
经验不够,读书来凑。 除非你的实战经验超级丰富,不然在面试时一定会遇到不熟悉的议题;面对无法回答的...
聊完了区网中设备与设备的连结後,我们来近距离看看这三大设备:AP, Switch 和 Router ...
如果要在 Linux 里面建立捷径,可使用已下语法: ln -s /usr/local/openlo...
vue.js2.0後版本推荐使用axios来完成ajax请求 为Promise-based HTTP...