mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 01:09:40 +08:00
Tighten up psf/black and flake8 (#2024)
* Tighten up psf/black and flake8 * Fix some tests * Fix some E741 * Fix some E741 * updating DIRECTORY.md Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@ -1,11 +1,14 @@
|
||||
"""
|
||||
Author : Mehdi ALAOUI
|
||||
|
||||
This is a pure Python implementation of Dynamic Programming solution to the longest increasing subsequence of a given sequence.
|
||||
This is a pure Python implementation of Dynamic Programming solution to the longest
|
||||
increasing subsequence of a given sequence.
|
||||
|
||||
The problem is :
|
||||
Given an array, to find the longest and increasing sub-array in that given array and return it.
|
||||
Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return [10, 22, 33, 41, 60, 80] as output
|
||||
Given an array, to find the longest and increasing sub-array in that given array and
|
||||
return it.
|
||||
Example: [10, 22, 9, 33, 21, 50, 41, 60, 80] as input will return
|
||||
[10, 22, 33, 41, 60, 80] as output
|
||||
"""
|
||||
from typing import List
|
||||
|
||||
@ -21,11 +24,13 @@ def longest_subsequence(array: List[int]) -> List[int]: # This function is recu
|
||||
[8]
|
||||
>>> longest_subsequence([1, 1, 1])
|
||||
[1, 1, 1]
|
||||
>>> longest_subsequence([])
|
||||
[]
|
||||
"""
|
||||
array_length = len(array)
|
||||
if (
|
||||
array_length <= 1
|
||||
): # If the array contains only one element, we return it (it's the stop condition of recursion)
|
||||
# If the array contains only one element, we return it (it's the stop condition of
|
||||
# recursion)
|
||||
if array_length <= 1:
|
||||
return array
|
||||
# Else
|
||||
pivot = array[0]
|
||||
|
Reference in New Issue
Block a user