vendredi 26 mars 2021

Java -- ++ in if statement

I am confused about the difference between this 3 statement. What differences between each of them? I know the differences between first and third, but how different is between first and second, and second to third. Thank!

    // first
    for (int i = 0, j = 0; i < s.length(); i++) {
        if (count[s.charAt(i)]-- > 0) {
            tLen--;
        }
    }

    // second
    for (int i = 0, j = 0; i < s.length(); i++) {
        count[s.charAt(i)]--;
        if (count[s.charAt(i)] > 0) {
            tLen--;
        }
    }
    

    // third
    for (int i = 0, j = 0; i < s.length(); i++) {
        
        if (count[s.charAt(i)] > 0) {
            count[s.charAt(i)]--;
            tLen--;
        }
    }

Aucun commentaire:

Enregistrer un commentaire