Share my c++ solution


  • 0
    Z
    vector<int> getRow(int rowIndex) {
       vector<int> res;
       res.push_back(1);
    
       int mid = rowIndex / 2;
       for (int i = 1; i <= mid; i++)
       {
           long tmp = res[i-1];
           tmp*=(rowIndex-i+1);
           tmp/=i;
           res.push_back((int)tmp);
       }
       int m = (rowIndex + 1)/2;
       for (int i = m - 1; i >= 0; i--)
       {
           res.push_back(res[i]);
       }
       return res;
    }

Log in to reply
 

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