[Python] Finding the maximum number in a list python 3

Discussão em 'Python' iniciado por Stack, Fevereiro 18, 2025.

  1. Stack

    Stack Membro Participativo

    Below is my code to return the maximum number in the list, but for some reason it returns 9.

    I must clarify that the aim of this program is to compare BigO complexities of quadratic - O(n^2) with Linear O(n) . So I am looking for a way to solve this problem with nested loop which will represent O(n^2). Please give a nested loop solution

    a = [2,4,7,2,1,9,33,105,2,3,7,300,4,9]
    maxa = a[0]
    for i in a:
    for j in a:
    if (i>j):
    maxa = i
    print("greatest number is " + str(maxa))


    help figure what the problem is

    Continue reading...

Compartilhe esta Página