|
5 | 5 | importjava.util.List;
|
6 | 6 | importjava.util.Map;
|
7 | 7 |
|
8 |
| -/** |
9 |
| - * 1182. Shortest Distance to Target Color |
10 |
| - * |
11 |
| - * You are given an array colors, in which there are three colors: 1, 2 and 3. |
12 |
| - * You are also given some queries. Each query consists of two integers i and c, |
13 |
| - * return the shortest distance between the given index i and the target color c. If there is no solution return -1. |
14 |
| - * |
15 |
| - * Example 1: |
16 |
| - * Input: colors = [1,1,2,1,3,2,2,3,3], queries = [[1,3],[2,2],[6,1]] |
17 |
| - * Output: [3,0,3] |
18 |
| - * Explanation: |
19 |
| - * The nearest 3 from index 1 is at index 4 (3 steps away). |
20 |
| - * The nearest 2 from index 2 is at index 2 itself (0 steps away). |
21 |
| - * The nearest 1 from index 6 is at index 3 (3 steps away). |
22 |
| - * |
23 |
| - * Example 2: |
24 |
| - * Input: colors = [1,2], queries = [[0,3]] |
25 |
| - * Output: [-1] |
26 |
| - * Explanation: There is no 3 in the array. |
27 |
| - * |
28 |
| - * Constraints: |
29 |
| - * 1 <= colors.length <= 5*10^4 |
30 |
| - * 1 <= colors[i] <= 3 |
31 |
| - * 1 <= queries.length <= 5*10^4 |
32 |
| - * queries[i].length == 2 |
33 |
| - * 0 <= queries[i][0] < colors.length |
34 |
| - * 1 <= queries[i][1] <= 3 |
35 |
| - * */ |
36 | 8 | publicclass_1182 {
|
37 | 9 | publicstaticclassSolution1 {
|
38 | 10 | publicList<Integer>shortestDistanceColor(int[]colors,int[][]queries) {
|
|