Is there any problem with OJ? I didn't return but it is accepted


  • 0
    M

    It is a c++ solution.
    OJ accept the following code without return.
    And 25 / 25 test cases passed.

    class Solution {
    public:
        void permute_recur(vector<vector<int> > &pers, int *mark, vector<int> &per, vector<int> &num) {
            if (per.size() == num.size()) {
                pers.push_back(per);
                return ;
            }
            
            for (int i = 0; i < num.size(); i++) {
                if (mark[i] == 1) continue;
                mark[i] = 1;
                per.push_back(num[i]);
                permute_recur(pers, mark, per, num);
                per.pop_back();
                mark[i] = 0;
            }
            
            return ;
        }
        
        vector<vector<int> > permute(vector<int> &num) {
            vector<vector<int> > pers;
            if (num.size() == 0)
                return pers;
                
            vector<int> per;
            int *mark = new int[num.size()];
            memset(mark, 0, 4*num.size());
            permute_recur(pers, mark, per, num);
        }
    };

  • 0

    Although it happens to work, this is undefined behavior according to C++ standard.

    http://stackoverflow.com/questions/20963347/missing-return-statement-in-c-can-still-work


Log in to reply
 

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