Python Forum
I need some help with my code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I need some help with my code
#6
(Feb-27-2021, 08:19 PM)SantiagoPB Wrote:
def longestIncreasing(arr):
    res = []
    temp = [arr[0]]
    for i in range(1, len(arr)):
        if arr[i] > arr[i-1]:
            temp.append(arr[i])
            if i == len(arr)-1 and len(temp) > len(res): res = temp
        else:
            if len(temp) > len(res): res = temp
            temp = [arr[i]]
    return res

def output(arr):
    for n, i in enumerate(arr):
        if n == len(arr)-1: print(i)
        else: print(i, end = ' ')

if __name__ == "__main__":
    arr = [1, 7, 8, 3, 4, 6, 8, 9, 0, 5, 1, 2, 3]
    output(longestIncreasing(arr))
Output:
3 4 6 8 9
Reply


Messages In This Thread
I need some help with my code - by SantiagoPB - Feb-27-2021, 08:19 PM
RE: I need some help with my code - by Larz60+ - Feb-28-2021, 01:23 AM
RE: I need some help with my code - by Serafim - Feb-28-2021, 02:03 PM
RE: I need some help with my code - by SantiagoPB - Feb-28-2021, 02:14 PM
RE: I need some help with my code - by Larz60+ - Feb-28-2021, 06:03 PM
RE: I need some help with my code - by naughtyCat - Aug-27-2021, 04:53 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020