kk
This commit is contained in:
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
5
.idea/codeStyles/codeStyleConfig.xml
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
<component name="ProjectCodeStyleConfiguration">
|
||||
<state>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" />
|
||||
</state>
|
||||
</component>
|
15
.idea/git_toolbox_prj.xml
generated
Normal file
15
.idea/git_toolbox_prj.xml
generated
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GitToolBoxProjectSettings">
|
||||
<option name="commitMessageIssueKeyValidationOverride">
|
||||
<BoolValueOverride>
|
||||
<option name="enabled" value="true" />
|
||||
</BoolValueOverride>
|
||||
</option>
|
||||
<option name="commitMessageValidationEnabledOverride">
|
||||
<BoolValueOverride>
|
||||
<option name="enabled" value="true" />
|
||||
</BoolValueOverride>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@@ -1,5 +1,9 @@
|
||||
package com.dota;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
// 按两次 Shift 打开“随处搜索”对话框并输入 `show whitespaces`,
|
||||
// 然后按 Enter 键。现在,您可以在代码中看到空格字符。
|
||||
public class Main {
|
||||
@@ -17,3 +21,12 @@ public class Main {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Solution1 {
|
||||
public List<List<Integer>> permuteUnique(int[] nums) {
|
||||
Arrays.sort(nums);
|
||||
List<List<Integer>> res = new ArrayList<>();
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
@@ -1,62 +1,63 @@
|
||||
package com.dota;
|
||||
|
||||
public class Solution {
|
||||
// 1423. 可获得的最大点数
|
||||
public int maxScore(int[] cardPoints, int k) {
|
||||
int max;
|
||||
int n = cardPoints.length;
|
||||
int len = n - k;
|
||||
int sum = 0;
|
||||
for (int cardPoint : cardPoints) {
|
||||
sum += cardPoint;
|
||||
}
|
||||
// 1423. 可获得的最大点数
|
||||
public int maxScore(int[] cardPoints, int k) {
|
||||
int max;
|
||||
int n = cardPoints.length;
|
||||
int len = n - k;
|
||||
int sum = 0;
|
||||
for (int cardPoint : cardPoints) {
|
||||
sum += cardPoint;
|
||||
}
|
||||
|
||||
|
||||
int temp = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
temp += cardPoints[i];
|
||||
}
|
||||
int temp = 0;
|
||||
for (int i = 0; i < len; i++) {
|
||||
temp += cardPoints[i];
|
||||
}
|
||||
|
||||
max = temp;
|
||||
for (int i = len; i < n; i++) {
|
||||
temp -= cardPoints[i - len];
|
||||
temp += cardPoints[i];
|
||||
if (temp < max) {
|
||||
max = temp;
|
||||
}
|
||||
}
|
||||
max = temp;
|
||||
for (int i = len; i < n; i++) {
|
||||
temp -= cardPoints[i - len];
|
||||
temp += cardPoints[i];
|
||||
if (temp < max) {
|
||||
max = temp;
|
||||
}
|
||||
}
|
||||
|
||||
return sum - max;
|
||||
}
|
||||
return sum - max;
|
||||
}
|
||||
|
||||
// 2048. 下一个更大的数值平衡数
|
||||
public int nextBeautifulNumber(int n) {
|
||||
while(!ok(++n)) {
|
||||
}
|
||||
return n;
|
||||
}
|
||||
private boolean ok(int n){
|
||||
if (n==0) {
|
||||
return false;
|
||||
}
|
||||
// 2048. 下一个更大的数值平衡数
|
||||
public int nextBeautifulNumber(int n) {
|
||||
while (!ok(++n)) {
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
int[] dp = new int[10];
|
||||
while (n!=0) {
|
||||
int t = n%10;
|
||||
dp[t]++;
|
||||
if (dp[t] > t) {
|
||||
return false;
|
||||
}
|
||||
private boolean ok(int n) {
|
||||
if (n == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
n/=10;
|
||||
}
|
||||
int[] dp = new int[10];
|
||||
while (n != 0) {
|
||||
int t = n % 10;
|
||||
dp[t]++;
|
||||
if (dp[t] > t) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i = 1; i < dp.length; i++) {
|
||||
if (dp[i]!=0 && dp[i]!=i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
n /= 10;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
for (int i = 1; i < dp.length; i++) {
|
||||
if (dp[i] != 0 && dp[i] != i) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
24
src/main/java/com/dota/arr/_2225/Solution.java
Normal file
24
src/main/java/com/dota/arr/_2225/Solution.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.dota.arr._2225;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
//2225. 找出输掉零场或一场比赛的玩家
|
||||
class Solution {
|
||||
public List<List<Integer>> findWinners(int[][] matches) {
|
||||
List<List<Integer>> res = new ArrayList<List<Integer>>();
|
||||
res.add(new ArrayList<>());
|
||||
res.add(new ArrayList<>());
|
||||
int[] book = new int[10001];
|
||||
for (int[] match : matches) {
|
||||
book[match[1]]++;
|
||||
}
|
||||
for (int i = 0; i < book.length; i++) {
|
||||
if (book[i] == 1) {
|
||||
res.get(1).add(i);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
41
src/main/java/com/dota/bucket/Solution.java
Normal file
41
src/main/java/com/dota/bucket/Solution.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.dota.bucket;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
class Solution {
|
||||
public boolean containsNearbyAlmostDuplicate(int[] nums, int k, int t) {
|
||||
Map<Long, Long> map = new HashMap<>();
|
||||
for (int i = 0; i < nums.length; i++) {
|
||||
long id = getId(nums[i], t + 1);
|
||||
if (map.containsKey(id)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
map.put(id, (long) nums[i]);
|
||||
|
||||
if (map.containsKey(id + 1) && Math.abs(map.get(id + 1) - nums[i]) <= t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (map.containsKey(id - 1) && Math.abs(map.get(id - 1) - nums[i]) <= t) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i >= k) {
|
||||
map.remove(getId(nums[i - k], t + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public long getId(int x, int w) {
|
||||
if (x >= 0) {
|
||||
return x / w;
|
||||
}
|
||||
|
||||
return (x + 1) / w - 1;
|
||||
}
|
||||
}
|
@@ -5,6 +5,19 @@ package com.dota.map;
|
||||
*/
|
||||
class Solution {
|
||||
|
||||
public int maxDistance(int[] colors) {
|
||||
int max = 0;
|
||||
for (int i = 0; i < colors.length; i++) {
|
||||
for (int j = i+1; j < colors.length; j++) {
|
||||
if (colors[i] != colors[j]) {
|
||||
max = Math.max(max, j-i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return max;
|
||||
}
|
||||
|
||||
public String repeatLimitedString(String s, int repeatLimit) {
|
||||
var dp = new int[26];
|
||||
for (char c : s.toCharArray()) {
|
||||
@@ -27,7 +40,7 @@ class Solution {
|
||||
break;
|
||||
}
|
||||
|
||||
res.append((char)('a' + j));
|
||||
res.append((char) ('a' + j));
|
||||
dp[j]--;
|
||||
} else {
|
||||
res.append(String.valueOf((char) ('a' + i)).repeat(dp[i]));
|
||||
|
3
src/main/kotlin/A.kt
Normal file
3
src/main/kotlin/A.kt
Normal file
@@ -0,0 +1,3 @@
|
||||
fun main() {
|
||||
println("123")
|
||||
}
|
Reference in New Issue
Block a user