Skip to content

Commit 799e137

Browse files
committed
update
1 parent 784f9c2 commit 799e137

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Runtime 2 ms Beats 100.00%
2+
// Memory 42.04 MB Beats 100.00%
3+
// .
4+
// T:O(n), S:O(n)
5+
//
6+
class Solution {
7+
public int maxSum(int[] nums) {
8+
int ret = 0, maxNonPosi = Integer.MIN_VALUE;
9+
HashSet<Integer> record = new HashSet<>();
10+
for (int num : nums) {
11+
if (num > 0) {
12+
record.add(num);
13+
} else {
14+
maxNonPosi = Math.max(maxNonPosi, num);
15+
}
16+
}
17+
if (record.size() == 0) {
18+
return maxNonPosi;
19+
}
20+
21+
for (int i : record) {
22+
ret += i;
23+
}
24+
25+
return ret;
26+
}
27+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Runtime 0 ms Beats 100.00%
2+
// Memory 40.98 MB Beats 65.69%
3+
// .
4+
// T:O(1), S:O(1)
5+
//
6+
class Solution {
7+
public int maxContainers(int n, int w, int maxWeight) {
8+
return Math.min(n * n, maxWeight / w);
9+
}
10+
}

0 commit comments

Comments
 (0)