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

Commit 5bcd042

Browse files
add 2070
1 parent c0c4cc1 commit 5bcd042

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

README.md

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

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2070|[Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2068.java) ||Easy||
1112
|2068|[Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2068.java) ||Easy||
1213
|2063|[Vowels of All Substrings](https://leetcode.com/problems/vowels-of-all-substrings/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2063.java) ||Medium||
1314
|2062|[Count Vowel Substrings of a String](https://leetcode.com/problems/count-vowel-substrings-of-a-string/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2062.java) ||Easy||
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Arrays;
4+
5+
public class _2070 {
6+
public static class Solution1 {
7+
public int[] maximumBeauty(int[][] items, int[] queries) {
8+
int len = queries.length;
9+
Arrays.sort(items, (a, b) -> Integer.compare(a[0], b[0]));
10+
int[][] queryPairs = new int[len][2];
11+
for (int i = 0; i < len; i++) {
12+
queryPairs[i] = new int[]{queries[i], i};
13+
}
14+
Arrays.sort(queryPairs, (a, b) -> Integer.compare(a[0], b[0]));
15+
int[] ans = new int[len];
16+
int j = 0;
17+
int max = 0;
18+
for (int i = 0; i < len; i++) {
19+
int[] queryPair = queryPairs[i];
20+
int price = queryPair[0];
21+
int index = queryPair[1];
22+
while (j < items.length && items[j][0] <= price) {
23+
max = Math.max(max, items[j][1]);
24+
j++;
25+
}
26+
ans[index] = max;
27+
}
28+
return ans;
29+
}
30+
}
31+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.fishercoder;
2+
3+
import com.fishercoder.common.utils.CommonUtils;
4+
import com.fishercoder.solutions._2070;
5+
import org.junit.BeforeClass;
6+
import org.junit.Test;
7+
8+
import static org.junit.Assert.assertArrayEquals;
9+
10+
public class _2070Test {
11+
private static _2070.Solution1 solution1;
12+
private static int[][] items;
13+
private static int[] queries;
14+
private static int[] expected;
15+
16+
@BeforeClass
17+
public static void setup() {
18+
solution1 = new _2070.Solution1();
19+
}
20+
21+
@Test
22+
public void test1() {
23+
items = CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2],[3,2],[2,4],[5,6],[3,5]");
24+
queries = new int[]{1, 2, 3, 4, 5, 6};
25+
expected = new int[]{2, 4, 5, 5, 6, 6};
26+
assertArrayEquals(expected, solution1.maximumBeauty(items, queries));
27+
}
28+
29+
@Test
30+
public void test2() {
31+
items = CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[1,2],[1,2],[1,3],[1,4]");
32+
queries = new int[]{1};
33+
expected = new int[]{4};
34+
assertArrayEquals(expected, solution1.maximumBeauty(items, queries));
35+
}
36+
37+
@Test
38+
public void test3() {
39+
items = CommonUtils.convertLeetCodeIrregularLengths2DArrayInputIntoJavaArray("[10,1000]");
40+
queries = new int[]{5};
41+
expected = new int[]{0};
42+
assertArrayEquals(expected, solution1.maximumBeauty(items, queries));
43+
}
44+
45+
}

0 commit comments

Comments
 (0)