-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathSolution496.java
32 lines (26 loc) · 898 Bytes
/
Solution496.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
package leetcode.simulate;
import java.util.Arrays;
public class Solution496 {
public static void main(String[] args) {
System.out.println(Arrays.toString(new Solution496().nextGreaterElement(new int[]{4, 1, 2}, new int[]{1, 3, 4, 2})));;
}
public int[] nextGreaterElement(int[] nums1, int[] nums2) {
int[] res = new int[nums1.length];
Arrays.fill(res, -1);
for (int i = 0; i < nums1.length; i++) {
for (int j = 0; j < nums2.length; j++) {
if (nums1[i] == nums2[j]) {
j++;
while (j < nums2.length) {
if (nums2[j] > nums1[i]) {
res[i] = nums2[j];
break;
}
j++;
}
}
}
}
return res;
}
}