Why does the test fail when the same set as the expected is returned but the elements are in different order ?


  • 0
    A

    public class Solution {

    public List<String> generateParenthesis(int n){
        
        List<String> r = new ArrayList();
        if(n == 1){
            r.add("()");
            return r;
        }        
    
        List<String> p = generateParenthesis(n-1);
        
        for(int i = 0; i<p.size(); i++ ){
            r.add("("+p.get(i)+")");
            r.add(p.get(i)+"()");
            if(i != p.size()-1){
                r.add("()"+p.get(i));
            }
        }
    
        return r;   
    

    }
    }


  • 0
    S

    Yeah I am having the same problem as well!


  • 0
    N

    hi, can you make sure your solution can generate (())(()) when N=4.
    ( I don't think it can. )


Log in to reply
 

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