Skip to content

Commit

Permalink
add 496-Next-Greater-Element-I.java
Browse files Browse the repository at this point in the history
  • Loading branch information
MukulGaur committed Nov 6, 2022
1 parent 3cfb9a5 commit e666953
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions java/496-Next-Greater-Element-I.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
class Solution {
public int[] nextGreaterElement(int[] nums1, int[] nums2) {

int[] res = new int[nums1.length];
int counter=0;

for(int i: nums1){
res[counter++]=ans(i, nums2);
}

return res;

}

private int ans(int i, int[] nums){
for(int n=0; n<nums.length; n++){
if(nums[n]==i){
for(int j=n+1; j<nums.length; j++){
if(nums[j]>i)
return nums[j];
}
}
}
return -1;
}
}

0 comments on commit e666953

Please sign in to comment.