Skip to content

Commit

Permalink
Time: 2 ms (15.54%), Space: 5.1 MB (21.51%) - LeetHub
Browse files Browse the repository at this point in the history
  • Loading branch information
hovanhoa committed Nov 16, 2024
1 parent 8b45ad9 commit 8d635ac
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions 0496-next-greater-element-i/0496-next-greater-element-i.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
func nextGreaterElement(nums1 []int, nums2 []int) []int {
ans := make([]int, len(nums1))
m := map[int]int{}
for i, v := range nums1 {
m[v] = i
}

for i, v := range nums2 {
if _, ok := m[v]; !ok {
continue
} else {
idx := m[v]
ans[idx] = -1
for j := i + 1; j < len(nums2); j++ {
if nums2[j] > nums2[i] {
ans[idx] = nums2[j]
break
}
}
}
}

return ans


}

0 comments on commit 8d635ac

Please sign in to comment.