1 | class Solution { |
注意题目没有说明存在多张相同的机票,但是需要处理该情况。Destination 类虽然没有用到 hashCode() 和 equals() 方法,但是根据规范,还是建议实现这两个方法,TreeSet 比较时仅使用了 compareTo() 方法,此时需要注意对索引的处理,避免相同机票在 Set 中被去重。
Hierholzer
1 | class Solution { |
Reference
332. Reconstruct Itinerary
Comparable (Java Platform SE 8 )
TreeSet (Java Platform SE 8 )