Understanding the most voted code

  • 0

    Here is the last function from the most voted code:

    private void getLadders(String start, String currLadder, LinkedList<String> p, ArrayList<LinkedList<String>> solu, 
                            HashMap<String, Queue<String>> adjMap, int len){
            solu.add(new ArrayList<String> (p));
        else if(len > 0) {
            Queue<String> adjs = adjMap.get(currLadder);
            for(String lad : adjs){
                getLadders(start, lad, p, solu, adjMap, len-1);

    p is defined as LinkedList type. But in third line, solu.add(new ArrayList<String> (p)); Is it trying to convert p into arraylist type? I am new to Java.

  • 0

    The short answer is yes. Or more precisely, new ArrayList(p) creates a new ArrayList and copies all elements from the LinkedList p to it.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.