Output Limit Exceeded, but I think my answer is correct

  • 1

    The solution is DFS. I tried {0,0,0,1,9} and it returns correct answer. Why do I get Output Limit Exceeded? Thanks.

     vector<vector<int> > permuteUnique(vector<int> &num) {
            size_t size = num.size();
            vector<vector<int>> vecs;
            if(size==0) {
                return vecs;
            vector<int> vec;
            sort(num.begin(), num.end());
            helper(num, 0, vecs);
            return vecs;
        void helper(vector<int> &num, int index, vector<vector<int>> &vecs) {
            if(index==num.size()) {
          for(size_t i=index; i<num.size(); ++i) {
    			if(i==index||i>index&&num[i]!=num[index]) {
    				swap(num[i], num[index]);
    				helper(num, index+1, vecs);
    				swap(num[i], num[index]);

  • 5

    Your output has duplicates. Try input {0, 0, 1, 1} with your code

  • 0

    Thank you so much. I came up with the same problem and your test case inspired me!

Log in to reply

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