Skip to content

Commit 725bca5

Browse files
authored
Update README.md
1 parent eaa58a6 commit 725bca5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@ Input: [10, 70, 20, 30, 50, 11, 30]
1111
Output: [[110], [10, 20, 30, 50]]
1212

1313

14+
## Implementation 1 : Dynamin Programming O(n^2)
15+
```java
16+
class Solution
17+
{
18+
public int maxSumIS(int nums[], int n)
19+
{
20+
if(nums == null || nums.length == 0)
21+
return Integer.MIN_VALUE;
22+
int length = nums.length;
23+
int[] dpTable = nums.clone();
24+
int maxSum = nums[0];
25+
for(int i = 1; i < length; i++) {
26+
for(int j = 0; j < i; j++) {
27+
if(nums[j] < nums[i] && dpTable[j] + nums[i] > dpTable[i] ) {
28+
dpTable[i] = dpTable[j] + nums[i];
29+
maxSum = Math.max(maxSum, dpTable[i]);
30+
}
31+
}
32+
}
33+
return maxSum;
34+
}
35+
}
36+
```
37+
1438
```java
1539
public static List<List<Integer>> maxSumIncreasingSubsequence(int[] nums) {
1640
if(nums == null || nums.length == 0) {

0 commit comments

Comments
 (0)