Skip to content

Improved tasks 2597, 2600, 2601 #1528

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sonar.coverage.jacoco.xmlReportPaths=build/jacoco/test/jacocoTestReport.xml
org.gradle.jvmargs=-Xms256m -Xmx1024m
org.gradle.jvmargs=-Xms512m -Xmx2048m
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ public int beautifulSubsets(int[] nums, int k) {
map.put(n, map.getOrDefault(n, 0) + 1);
}
int res = 1;
for (int key : map.keySet()) {
if (!map.containsKey(key - k)) {
if (!map.containsKey(key + k)) {
res *= 1 << map.get(key);
} else {
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (!map.containsKey(entry.getKey() - k)) {
if (map.containsKey(entry.getKey() + k)) {
List<Integer> freq = new ArrayList<>();
int localKey = key;
int localKey = entry.getKey();
while (map.containsKey(localKey)) {
freq.add(map.get(localKey));
localKey += k;
}
res *= helper(freq);
} else {
res *= 1 << entry.getValue();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

// #Easy #Math #Greedy #2023_08_29_Time_1_ms_(100.00%)_Space_40.3_MB_(19.10%)

@SuppressWarnings("java:S1172")
public class Solution {
public int kItemsWithMaximumSum(int numOnes, int numZeros, int numNegOnes, int k) {
if (k <= numOnes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ public boolean primeSubOperation(int[] nums) {
if (pos == -1 && n <= prev) {
return false;
}
prev = n - (pos == -1 ? 0 : (pos < 0 ? primes[-pos - 2] : primes[pos]));
final int index;
if (pos == -1) {
index = 0;
} else {
index = pos < 0 ? primes[-pos - 2] : primes[pos];
}
prev = n - index;
}
return true;
}
Expand Down