forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2399.java
33 lines (31 loc) · 981 Bytes
/
_2399.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.fishercoder.solutions;
import java.util.HashMap;
import java.util.Map;
public class _2399 {
public static class Solution1 {
public boolean checkDistances(String s, int[] distance) {
Map<Character, int[]> map = new HashMap<>();
int i = 0;
for (char c : s.toCharArray()) {
if (!map.containsKey(c)) {
map.put(c, new int[]{-1, -1});
}
int[] indices = map.get(c);
if (indices[0] == -1) {
indices[0] = i;
} else {
indices[1] = i;
}
i++;
}
for (char c : map.keySet()) {
int index = c - 'a';
int[] indices = map.get(c);
if (distance[index] + 1 != indices[1] - indices[0]) {
return false;
}
}
return true;
}
}
}