mercredi 5 juin 2019

Complexity: Conditional operator vs if-else [duplicate]

This question already has an answer here:

I am working on a simple code algorithm with Java, and I am wondering there may be a difference between ? : and if-else when calculating the time complexity. I think they both have the same time complexity, but I am not sure...

For example:

if (number == num) {
    count += 1;
}
else {
    count -= 1;
}

and

count += (number == num) ? 1 : -1;

Really thank you if you can tell me the difference between them :-)

Aucun commentaire:

Enregistrer un commentaire