Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 0a8717d

Browse files
window sliding technique
1 parent c1ccbb8 commit 0a8717d

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

‎PreffixSumSlidingWindow/.idea/workspace.xml

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
1.1 KB
Binary file not shown.

‎PreffixSumSlidingWindow/src/problems/SumOfSubset.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ public class SumOfSubset {
55

66
public static int maxSumOfSubsetK(int [] set, int k) {
77
int limit = set.length;
8+
if(k < limit)
9+
return -1;
810
int acc = 0;
911
for (int i=0; i<k ; i++) {
1012
acc += set[i];
@@ -21,8 +23,11 @@ public static int maxSumOfSubsetK(int [] set, int k) {
2123
public static void test1() {
2224
int [][] set = {
2325
{5 , 2 , -1 , 0 , 3}
26+
,{100, 200, 300,400}
27+
,{1, 4, 2, 10, 23, 3, 1, 0, 20}
28+
,{4, 2, 10, 23}
2429
};
25-
System.out.println(maxSumOfSubsetK(set[0], 3));
30+
System.out.println(maxSumOfSubsetK(set[2], 4));
2631
}
2732

2833

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /