Minor changes

This commit is contained in:
Vitor Oliveira 2021-04-10 10:41:01 -07:00
parent ce0d1863a2
commit 1c9a26f389

View file

@ -18,7 +18,7 @@
#
# Input: nums1 = [2,4], nums2 = [1,2,3,4]
# Output: [3,-1]
#
#
# Explanation:
# For number 2 in the first array, the next greater number for it in the second array is 3.
# For number 4 in the first array, there is no next greater number for it in the second array, so output -1.
@ -27,18 +27,18 @@
# @param {Integer[]} nums2
# @return {Integer[]}
def next_greater_element(nums1, nums2)
nums1.each_with_index do |value, pointer1|
nums1.each_with_index do |nums1_value, pointer1|
max = 0
pos_nums2 = nums2.find_index(value)
pos_nums2 = nums2.find_index(nums1_value)
nums2[pos_nums2..nums2.count].each do |value|
if value > nums1[pointer1]
max = value
nums2[pos_nums2..nums2.count].each do |nums2_value|
if nums2_value > nums1_value
max = nums2_value
break
end
end
nums1[pointer1] = (nums1[pointer1] < max ? max : -1)
nums1[pointer1] = (nums1_value < max ? max : -1)
end
nums1