Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 8ff22ca

Browse files
add 2399
1 parent b10f4e8 commit 8ff22ca

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|------|----------------|------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------|-------------
11-
| 2395 |[Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2395.java) || Easy ||
11+
| 2399 |[Check Distances Between Same Letters](https://leetcode.com/problems/check-distances-between-same-letters/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2399.java) || Medium ||
12+
| 2395 |[Find Subarrays With Equal Sum](https://leetcode.com/problems/find-subarrays-with-equal-sum/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2395.java) || Easy ||
1213
| 2380 |[Time Needed to Rearrange a Binary String](https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2380.java) || Medium ||
1314
| 2379 |[Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2379.java) || Easy ||
1415
| 2367 |[Number of Arithmetic Triplets](https://leetcode.com/problems/number-of-arithmetic-triplets/)| [Java](../master/src/main/java/com/fishercoder/solutions/_2367.java) || Easy ||
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
public class _2399 {
7+
public static class Solution1 {
8+
public boolean checkDistances(String s, int[] distance) {
9+
Map<Character, int[]> map = new HashMap<>();
10+
int i = 0;
11+
for (char c : s.toCharArray()) {
12+
if (!map.containsKey(c)) {
13+
map.put(c, new int[]{-1, -1});
14+
}
15+
int[] indices = map.get(c);
16+
if (indices[0] == -1) {
17+
indices[0] = i;
18+
} else {
19+
indices[1] = i;
20+
}
21+
i++;
22+
}
23+
for (char c : map.keySet()) {
24+
int index = c - 'a';
25+
int[] indices = map.get(c);
26+
if (distance[index] + 1 != indices[1] - indices[0]) {
27+
return false;
28+
}
29+
}
30+
return true;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)