kk
This commit is contained in:
16
src/main/java/com/dota/arr/_2656/Solution.java
Normal file
16
src/main/java/com/dota/arr/_2656/Solution.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.dota.arr._2656;
|
||||
|
||||
/**
|
||||
* 2656. K 个元素的最大和
|
||||
*/
|
||||
class Solution {
|
||||
public int maximizeSum(int[] nums, int k) {
|
||||
var max = nums[0];
|
||||
for (int num : nums) {
|
||||
if (num>max) {
|
||||
max = num;
|
||||
}
|
||||
}
|
||||
return max * k + k*(k-1)/2;
|
||||
}
|
||||
}
|
5
src/main/java/com/dota/rank/Solution.java
Normal file
5
src/main/java/com/dota/rank/Solution.java
Normal file
@@ -0,0 +1,5 @@
|
||||
package com.dota.rank;
|
||||
|
||||
public class Solution {
|
||||
|
||||
}
|
41
src/main/java/com/dota/treeMap/Solution.java
Normal file
41
src/main/java/com/dota/treeMap/Solution.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.dota.treeMap;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
public class Solution {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 2276. 统计区间中的整数数目
|
||||
*/
|
||||
|
||||
class CountIntervals {
|
||||
TreeMap<Integer, Integer> map = new TreeMap<>();
|
||||
int cnt = 0;
|
||||
|
||||
public CountIntervals() {
|
||||
|
||||
}
|
||||
|
||||
public void add(int left, int right) {
|
||||
Map.Entry<Integer, Integer> inte = map.floorEntry(right);
|
||||
while (inte != null && inte.getValue() >= left) {
|
||||
int l = inte.getKey();
|
||||
int r = inte.getValue();
|
||||
left = Math.min(l, left);
|
||||
right = Math.max(r, right);
|
||||
cnt -= r - l + 1;
|
||||
map.remove(l);
|
||||
inte = map.floorEntry(right);
|
||||
}
|
||||
|
||||
cnt += (right - left + 1);
|
||||
map.put(left, right);
|
||||
}
|
||||
|
||||
public int count() {
|
||||
return cnt;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user