找LeetCode上简单的题目来撑过30天啦(DAY20)

这题写凌晨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.

Example 1:
Input: s = "abcabcbb"
Output: 3
Explanation: The answer is "abc", with the length of 3.

Example 2:
Input: s = "bbbbb"
Output: 1
Explanation: The answer is "b", with the length of 1.

Example 3:
Input: s = "pwwkew"
Output: 3
Explanation: The answer is "wke", with the length of 3.
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.

Example 4:
Input: s = ""
Output: 0

Constraints:
• 0 <= s.length <= 5 * 104
• s consists of English letters, digits, symbols and spaces.

我的程序码

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了,加油加油,来去倒垃圾


<<:  Web应用扫描工具-Arachni小蜘蛛(下)

>>:  Day 20: SOLID 设计原则 — ISP (待改进中... )

Day29 - [Shioaji] 超入门!永丰证券程序交易API快速上手 (2)

今天来看一下如何使用Shioaji问回历史交易资料,不过在此先提醒一下,上一篇有讲到的永丰讲师的Yo...

[面试][资料库]面对高流量的的系统,会采取哪些措施?

经验不够,读书来凑。 除非你的实战经验超级丰富,不然在面试时一定会遇到不熟悉的议题;面对无法回答的...

讯息是怎麽进到网际网路的(二)?区网内的装置:AP, Switch, Router

聊完了区网中设备与设备的连结後,我们来近距离看看这三大设备:AP, Switch 和 Router ...

Linux 建立目录的捷径

如果要在 Linux 里面建立捷径,可使用已下语法: ln -s /usr/local/openlo...

[30天 Vue学好学满 DAY25] axios API

vue.js2.0後版本推荐使用axios来完成ajax请求 为Promise-based HTTP...