kk
This commit is contained in:
7
pom.xml
7
pom.xml
@@ -13,5 +13,12 @@
|
|||||||
<maven.compiler.target>17</maven.compiler.target>
|
<maven.compiler.target>17</maven.compiler.target>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
</properties>
|
</properties>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-collections4</artifactId>
|
||||||
|
<version>4.4</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
@@ -1,8 +1,18 @@
|
|||||||
package com.dota;
|
package com.dota;
|
||||||
|
|
||||||
|
import org.apache.commons.collections4.list.TreeList;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
public class Solution {
|
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. 可获得的最大点数
|
// 1423. 可获得的最大点数
|
||||||
public int maxScore(int[] cardPoints, int k) {
|
public int maxScore(int[] cardPoints, int k) {
|
||||||
int max;
|
int max;
|
||||||
|
30
src/main/java/com/dota/slidingWindow/_2653/Solution.java
Normal file
30
src/main/java/com/dota/slidingWindow/_2653/Solution.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
18
src/main/java/com/dota/str/_2109/Solution.java
Normal file
18
src/main/java/com/dota/str/_2109/Solution.java
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user