Skip to content

Commit e8dc7cc

Browse files
authored
Merge pull request #998 from agnihotriketan/patch-3
C# 300-Longest-Increasing-Subsequence.cs
2 parents 9673f8b + 7f1dbd2 commit e8dc7cc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Solution {
2+
public int LengthOfLIS(int[] nums) {
3+
int[] dp = new int[nums.Length];
4+
Array.Fill(dp, 1);
5+
6+
for (int i = nums.Length - 1; i >= 0; i--)
7+
{
8+
for (int j = i + 1; j < nums.Length; j++)
9+
{
10+
if (nums[i] < nums[j])
11+
{
12+
dp[i] = Math.Max(dp[i], 1 + dp[j]);
13+
}
14+
}
15+
}
16+
return dp.Max();
17+
}
18+
}

0 commit comments

Comments
 (0)