如果知道each_cons就很快可以解決
pi_array = []
min = 99999999999999999
@n = gets.to_i
@n.times do
pi = gets.to_i
pi_array << pi
end
new_pi = pi_array.sort
new_pi.each_cons(2) do |a,b|
if min > (b-a)
min = (b-a)
end
end
puts min
Written with StackEdit.
沒有留言:
張貼留言