Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1432 from MukulGaur/add-496-Next-Great…
Browse files Browse the repository at this point in the history
…er-Element-I

create 496-Next-Greater-Element-I.java
  • Loading branch information
Ahmad-A0 authored Dec 22, 2022
2 parents f6a3248 + e666953 commit d7bda02
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 d7bda02

Please sign in to comment.