This commit is contained in:
kkunkka
2025-03-31 11:31:59 +08:00
parent 671172ffc4
commit f9749da0e4
4 changed files with 65 additions and 0 deletions

View File

@@ -13,5 +13,12 @@
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
</project>

View File

@@ -1,8 +1,18 @@
package com.dota;
import org.apache.commons.collections4.list.TreeList;
import java.util.HashMap;
public class Solution {
public static void main(String[] args) {
var a = new TreeList<Integer>();
a.add(1);
a.add(2);
a.add(1);
System.out.println(a.get(2));
Integer.bitCount(1231);
}
// 1423. 可获得的最大点数
public int maxScore(int[] cardPoints, int k) {
int max;

View File

@@ -0,0 +1,30 @@
package com.dota.slidingWindow._2653;
class Solution {
public int[] getSubarrayBeauty(int[] nums, int k, int x) {
int n = nums.length;
int[] res = new int[n - k + 1];
int[] dp = new int[101];
for (int i = 0; i < k - 1; i++) {
dp[nums[i] + 50]++;
}
for (int i = k - 1; i < n; i++) {
dp[nums[i] + 50]++;
int left = x;
for (int j = 0; j < 101; j++) {
left -= dp[j];
if (left <= 0) {
res[i - k + 1] = j - 50;
if (res[i-k+1] > 0) {
res[i-k+1] = 0;
}
break;
}
}
dp[nums[i - k + 1] + 50]--;
}
return res;
}
}

View File

@@ -0,0 +1,18 @@
package com.dota.str._2109;
class Solution {
public String addSpaces(String s, int[] spaces) {
var sb = new StringBuilder();
int idx = 0;
int i = 0;
for (char c : s.toCharArray()) {
if (idx<spaces.length && i == spaces[idx]) {
sb.append(' ');
idx++;
}
sb.append(c);
i++;
}
return sb.toString();
}
}