kk
This commit is contained in:
@@ -5,14 +5,6 @@ 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;
|
||||||
|
42
src/main/java/com/dota/greedy/_2918/Solution.java
Normal file
42
src/main/java/com/dota/greedy/_2918/Solution.java
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
package com.dota.greedy._2918;
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public long minSum(int[] nums1, int[] nums2) {
|
||||||
|
long sum1 = 0, sum2 = 0, cnt1 = 0, cnt2 = 0;
|
||||||
|
for (int i : nums1) {
|
||||||
|
sum1 += i;
|
||||||
|
if (i == 0) cnt1++;
|
||||||
|
}
|
||||||
|
for (int i : nums2) {
|
||||||
|
sum2 += i;
|
||||||
|
if (i == 0) cnt2++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sum1 == sum2) {
|
||||||
|
if (cnt1 == cnt2) {
|
||||||
|
return sum1 + cnt1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cnt1 != 0 && cnt2 != 0) {
|
||||||
|
return sum1 + Math.max(cnt1, cnt2);
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sum1 < sum2) {
|
||||||
|
return minSum(nums2, nums1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cnt1 != 0 && cnt2 != 0) {
|
||||||
|
return Math.max(sum1 + cnt1, sum2 + cnt2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cnt2!=0) {
|
||||||
|
if(sum2+cnt2<=sum1){
|
||||||
|
return sum1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user