Why I got AC for this ridiculous code?


  • 1
    C

    If numRows > 0,this function will not get the result, as u know,I omit the code "return result". But I got AC 4 this code. Who can help me explain y?

    class Solution {
    public:
        vector<vector<int> > generate(int numRows) {
            vector<vector<int> > result;
            if(numRows <= 0)return result;
            vector<int> tmp1;
            vector<int> tmp2;
            for(int i = 1; i <= numRows;i++)
            {
                tmp2.clear();
                for(int j = 0; j < i;j++){
                    if(j == 0 || j == i - 1)tmp2.push_back(1);
                    else tmp2.push_back(tmp1[j] + tmp1[j - 1]);
                }
                tmp1 = tmp2;
                result.push_back(tmp1);
                
            }
            //return result;
        
        }
    };

Log in to reply
 

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