package com.fishercoder.solutions;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;

public class _332 {

    public static class Solution1 {
        /**
         * credit: https://discuss.leetcode.com/topic/36383/share-my-solution
         */
        public List<String> findItinerary(String[][] tickets) {
            Map<String, PriorityQueue<String>> flights = new HashMap<>();
            LinkedList<String> path = new LinkedList<>();
            for (String[] ticket : tickets) {
                flights.putIfAbsent(ticket[0], new PriorityQueue<>());
                flights.get(ticket[0]).add(ticket[1]);
            }
            dfs("JFK", flights, path);
            return path;
        }

        public void dfs(String departure, Map<String, PriorityQueue<String>> flights,
                        LinkedList path) {
            PriorityQueue<String> arrivals = flights.get(departure);
            while (arrivals != null && !arrivals.isEmpty()) {
                dfs(arrivals.poll(), flights, path);
            }
            path.addFirst(departure);
        }
    }
}

@@ -367,18 +367,26 @@
 ary(
+List%3CList%3C
 String
-%5B%5D%5B%5D
+%3E%3E
  tic
@@ -546,16 +546,20 @@
 or (
+List%3C
 String
-%5B%5D
+%3E
  tic
@@ -617,19 +617,23 @@
 t(ticket
-%5B0%5D
+.get(0)
 , new Pr
@@ -688,11 +688,15 @@
 cket
-%5B0%5D
+.get(0)
 ).ad
@@ -707,11 +707,15 @@
 cket
-%5B1%5D
+.get(1)
 );%0A 

Update _332.java (#95)