How can it say wrong?? I am confused!!


  • 0
    L

    public class Solution {

    public ArrayList<Integer> grayCode(int n) {
    
    ArrayList<Integer> l=new ArrayList<Integer>()
    
    if(n==0) {
    
        l.add(0);
    
        return l;
    
    }
    
    l.add(0);l.add(1);
    
    for(int i=2;i<=n;i++){
    
        for(int j=0;j<l.size();j++){
    
            l.set(j,l.get(j)<<1);
    
            l.add(l.get(j)+1);
    
        }
    
    }
    
    return l;
    
    }
    

    }

    Submit Solution
    Submission Result: Time Limit Exceeded


Log in to reply
 

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