Find a unique element in a compound array

后端 未结 7 1446
面向向阳花
面向向阳花 2021-01-26 12:34

I am trying to solve a problem where I need to find the airport code in an array of arrays of that represents the starting point of a multi-city flight plan. For example: Given

7条回答
  •  萌比男神i
    2021-01-26 13:12

    sorry i, have no enough time to explain my code - but i think nothing is such difficult not to figure out what is happening :)

    here is the working example

    def find_start_point(list)
        start = []
        finish = []
    
        list.each do |l|
            start.push(l[0])
            finish.push(l[1])
        end
    
        start.each do |st|
            if !finish.include? st
                return start.index(st)
            end
        end
    
    end
    

提交回复
热议问题