Leetcode(Longest Substring Without Repeating Characters)

建议安装油猴插件1433065-20190129235141631-908667503.png

效果如下

1433065-20190129235020821-1880456387.png
1433065-20190129235049569-73126815.png
1433065-20190129235107099-712733565.png

a

1433065-20181101215759720-261286259.png

C++

public class Solution {
    public int lengthOfLongestSubstring(String s) {
        int n = s.length();
        Set<Character> set = new HashSet<>();
        int ans = 0, i = 0, j = 0;
        while (i < n && j < n) {
            // try to extend the range [i, j]
            if (!set.contains(s.charAt(j))){
                set.add(s.charAt(j++));
                ans = Math.max(ans, j - i);
            }
            else {
                set.remove(s.charAt(i++));
            }
        }
        return ans;
    }
}

java

//if str is null,there is invalid parameters
if(str == null){
    throw new IlleagalArgumentException("invalid parameters");
//if length of the string is 0 or 1,there is no duplicate character and return to true
if(str.length() == 0 || str.length() == 1){
    return true;
}

//create HashTable,put the string into HashTable
HashSet<Character>hs = new HashSet<Character>();

for(int i = 0; i < str.length(); i++){
    if(hs.contains(str.charAt(i))){
        return false;//The same characters are shown in the hash table,so that there are repeated characters.
    }
    hs.add(str.charAt(i));
}

return true;

if(str == null){
    throw new IllegalArgumentExceptiono("invalid parameters");
}

//if the length of str is 0 or 1,so that there is no repeated characters,return true
if(str.length() == 0 || str.length() == 1){
    return true;
}

//create HashTable,put the string to HashTable
HashSet<Charagcter> hs = new HashSet<Character>();

for(int i = 0;i <str.length(); i++){
    if(hs.contains(sts.charAt(i))){
        return false;//There is same character in HashSet,so that there are repeated characters
    }
    hs.add(str.charAt(i));
}

return true;

信息熵模型 | Shannon's Entropy Model

Shannon's Entropy model

decision Tree set up branch

<font colort="blue size="6">uncertainty

The First ColumnThe Second Column
Batch_size批尺寸
epochwhen a full dataset cross over neural networks and return a time,the full process named a epoch
epochas the number of epoch increasing,the number of updates of weights in neural netwoks increase,and the curve changes from under-fitting to over-fitting.
iterationiteration = \(iteration = /frac{the sample size in epoch}{the sample size in batch(batch size)}\)
epochthere is a dataset of 2000 training samples.The 2000 samples are devided into 500 sizes of batch,so it takes 4 iterations to complete a epoch.
normal distribution\(f{1}{\sqrt{2\pi}\sigma}exp{-\frac{(x-mu)^2}{2\sigma^2}}\)
normal distribution\(f(x;\mu;\sigma)=\frac{1}{\sqrt{2\pi}\sigma}exp{-\frac{x-\mu)^2}{2\sigma^2}}\)
epochneeding 4 iteration to finish a epoch
information entropythe information entropy of a thing is the smallest space you need to store it on your hard disk
stochastic随机的
optimum最适宜的
anslengthOfLongSubString
SetRandomness , no subscript , no duplicate element

Set<Character> = new HashSet<>();
set.add("c");
set.add("b");
set.add("d");
set.add("a");
set.add("a");
System.out.println(set);
  • result
    • [a,b,c,d] //based on the results,we can see it is nondisordered and non repeatability
Hash<Character> hashSet = new HashSet<>();
hashSet.add("a");
hashSet("b");
hashSet("d");
hashSet("d");
Systeim.out.println(hashSet);
  • result
    • [a,b,d]
TreeSet<Integer> treeSet = new TreeSet<>();
    treeSet.add(10);
    treeSet.add(8);
    treeSet.add(15);    
    treeSet.add(11);
    treeSet.add(8);
    System.out.println(treeSet);
  • result
    • [8,10,11,15] //treesetsort sorts and delete repeated elements
public class Solution{
    public int lengthOfLongestSubString(String s){
        int n = s.length();
        int ans = 0;
        for(i = 1,i < n; i++){
            for(j = i+1; i < n; i++){
            if (allUnique(s,i,j)) ans = Math.max(ans, j-i); //java.lang.Math.max(parameter_1 , parameter_2) parameter is int , double , float ,long
        //allUnique() is public boolean allUnique()
            }
        }
    }
        return ans;
    }
    public boolean allUnique(String s, int start, int end) {
        Set<Character> set = new HashSet<>();   //set : out of order(inconsistent access sequence),no index and unrepeatable.
    //HahSet and TreeSet : HashSet'API is Hash Algorithms,TreeSet'API is binary tree
    for(int i = start, i < end; i++) {
        Character ch = s.charAt(i);
        if(set.contain(ch)){
            return false;
        }
        set.add(ch);
    }
    return true;
    }
char = 'a';
        Character ch1 = ch; //automatix packageing
        Character c = new Character(a);
        char c1 = c;    //automatic unpakaging
int t= 10;
Integer t1 = t; //automatic pakaging
Integer t = new Integer(10);
int t1 = t; //automatic unpacking
public class Text{

    public static void main(String args[]) {
        String s = "www.runoob.com"
            char result = s.charAt[8];
            System.out println(result);
    }
}

iteration is the times that batch finish one epoch

iteration is the times that batch finish one epoch

AP measures the quality of learned models in each category,and mAP measures the quality of learned modules in all categorie.After obtaining AP,the calculation of mAP is to take the average value of all mAP.

AP衡量的是学出来的模型在每个类别上的好坏,mAP衡量的是学出的模型在所有类别上的好坏,得到AP后mAP的计算就变得很简单了,就是取所有AP的平均值。

暴力法

publicclassSolution {
    public int lengthOfLongestSubstring(String s) {
        int n s.length;
        int ans = 0;
        for (i = 0; i < n; i++)
            for (int j = i+1; j <= n; j++)
                if (allUnique(s, i, j) ans = Math.max(ans, j - i);  //i = 0, j = 1, allUnique(asd, 0, 1), ans = Math.max(0, 1 - 0), return 1;  allUnique(asd, 0, 1), Set<Character> = new HashSet<>(); for (int i = 0; i < 1; i++) {Character ch = "asd".charAt(0), if (set.contain("a")) return false; set.add("a"); } retrurn true;
    public boolean allUnique(String s, int start, int end) {
        Set<Character> set= new HashSet<>();
        for (i = start; i < end; i++){
            Character ch = s.charAt(i);
            if (set.contains(ch)) return false;
            set.add(ch);
        }
        return true;
    }
}

转载于:https://www.cnblogs.com/hugeng007/p/9892836.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值