Skip to content

Commit ae5a529

Browse files
authored
Merge pull request prabhupant#365 from durid17/LIS
Longest Increasing Subsequence
2 parents 56aa65e + 79a4fae commit ae5a529

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
def LIS(arr):
2+
n = len(arr)
3+
if n == 0: return 0
4+
res = 1
5+
dp = [0] * n
6+
dp[0] = 1
7+
for i in range(1, n):
8+
dp[i] = 1;
9+
for j in range(0 , i):
10+
if arr[i] > arr[j]:
11+
dp[i] = max(dp[i] , dp[j] + 1)
12+
res = max(res , dp[i])
13+
return res

0 commit comments

Comments
 (0)