The method is:
List<Book> books = new List<Book>();
public List<Book> Shoot()
{
foreach(var b in books)
{
bool find = true;
foreach(var otherb in books)
{
if(otherb != b && otherb.Author == b.Author)
{
find = false;
}
}
if(find)
{
yield return b;
}
}
}
Normally, the time complexity will be O(books.Count^2), but there is a if(find) statement in the outer loop and it may change the loop times.
So my questions are:
- What is the time complexity of this method?
- How did you calculate it?
I'm waiting online for your answer.
Thank you in advance.