mirror of
https://github.com/TheAlgorithms/Ruby
synced 2025-01-14 08:01:05 +01:00
Minor changes
This commit is contained in:
parent
ce0d1863a2
commit
1c9a26f389
1 changed files with 7 additions and 7 deletions
|
@ -27,18 +27,18 @@
|
||||||
# @param {Integer[]} nums2
|
# @param {Integer[]} nums2
|
||||||
# @return {Integer[]}
|
# @return {Integer[]}
|
||||||
def next_greater_element(nums1, nums2)
|
def next_greater_element(nums1, nums2)
|
||||||
nums1.each_with_index do |value, pointer1|
|
nums1.each_with_index do |nums1_value, pointer1|
|
||||||
max = 0
|
max = 0
|
||||||
pos_nums2 = nums2.find_index(value)
|
pos_nums2 = nums2.find_index(nums1_value)
|
||||||
|
|
||||||
nums2[pos_nums2..nums2.count].each do |value|
|
nums2[pos_nums2..nums2.count].each do |nums2_value|
|
||||||
if value > nums1[pointer1]
|
if nums2_value > nums1_value
|
||||||
max = value
|
max = nums2_value
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
nums1[pointer1] = (nums1[pointer1] < max ? max : -1)
|
nums1[pointer1] = (nums1_value < max ? max : -1)
|
||||||
end
|
end
|
||||||
|
|
||||||
nums1
|
nums1
|
||||||
|
|
Loading…
Reference in a new issue