Leetcode in Java && Oracle
419 subscribers
8 photos
397 files
400 links
Second channel: @codeforces_java

Let's Develop Together!
Download Telegram
image_2021-11-09_01-58-29.png
50.4 KB
#N496. Next Greater Element I
problem link

#solution
class Solution {
public int[] nextGreaterElement(int[] nums1, int[] nums2) {
int[] res=new int[nums1.length];
boolean isFound;

for(int i=0; i<nums1.length; i++){
isFound=false;
for(int j=0; j<nums2.length; j++){
if(nums2[j]==nums1[i])
isFound=true;

if(isFound){
if(nums2[j]>nums1[i]){
res[i]=nums2[j];
break;
}
else if(j==nums2.length-1)
res[i]=-1;
}
}
}

return res;
}
}