One-way flight trip problem

后端 未结 18 1505

You are going on a one-way indirect flight trip that includes billions an unknown very large number of transfers.

  • You are not stoppi
18条回答
  •  无人及你
    2020-12-12 17:43

    Construct a hashtable and add each airport into the hash table.

    =

    Count for the airport increases if the airport is either the source or the destination. So for every airport the count will be 2 ( 1 for src and 1 for dst) except for the source and the destination of your trip which will have the count as 1.

    You need to look at each ticket at least once. So complexity is O(n).

提交回复
热议问题