Movatterモバイル変換


[0]ホーム

URL:


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

Commit1341e85

Browse files
authored
Improved tasks 2597, 2600, 2601
1 parentde73d15 commit1341e85

File tree

4 files changed

+15
-8
lines changed

4 files changed

+15
-8
lines changed

‎gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
sonar.coverage.jacoco.xmlReportPaths=build/jacoco/test/jacocoTestReport.xml
2-
org.gradle.jvmargs=-Xms256m -Xmx1024m
2+
org.gradle.jvmargs=-Xms512m -Xmx2048m

‎src/main/java/g2501_2600/s2597_the_number_of_beautiful_subsets/Solution.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ public int beautifulSubsets(int[] nums, int k) {
1515
map.put(n,map.getOrDefault(n,0) +1);
1616
}
1717
intres =1;
18-
for (intkey :map.keySet()) {
19-
if (!map.containsKey(key -k)) {
20-
if (!map.containsKey(key +k)) {
21-
res *=1 <<map.get(key);
22-
}else {
18+
for (Map.Entry<Integer,Integer>entry :map.entrySet()) {
19+
if (!map.containsKey(entry.getKey() -k)) {
20+
if (map.containsKey(entry.getKey() +k)) {
2321
List<Integer>freq =newArrayList<>();
24-
intlocalKey =key;
22+
intlocalKey =entry.getKey();
2523
while (map.containsKey(localKey)) {
2624
freq.add(map.get(localKey));
2725
localKey +=k;
2826
}
2927
res *=helper(freq);
28+
}else {
29+
res *=1 <<entry.getValue();
3030
}
3131
}
3232
}

‎src/main/java/g2501_2600/s2600_k_items_with_the_maximum_sum/Solution.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

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

5+
@SuppressWarnings("java:S1172")
56
publicclassSolution {
67
publicintkItemsWithMaximumSum(intnumOnes,intnumZeros,intnumNegOnes,intk) {
78
if (k <=numOnes) {

‎src/main/java/g2601_2700/s2601_prime_subtraction_operation/Solution.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ public boolean primeSubOperation(int[] nums) {
4343
if (pos == -1 &&n <=prev) {
4444
returnfalse;
4545
}
46-
prev =n - (pos == -1 ?0 : (pos <0 ?primes[-pos -2] :primes[pos]));
46+
finalintindex;
47+
if (pos == -1) {
48+
index =0;
49+
}else {
50+
index =pos <0 ?primes[-pos -2] :primes[pos];
51+
}
52+
prev =n -index;
4753
}
4854
returntrue;
4955
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp