Solution without using double


  • 0
    F
    class Solution {
    public:
        vector<int> getRow(int rowIndex) {
            vector<int > r;
            r.resize(rowIndex);
            r.push_back(1);
            if(rowIndex==0) return r;
            r.resize(rowIndex+1);
            r[0]=1;
            for(int i=1;i<=(rowIndex/2);i++){
                long long int val1=1;
                long long int val2=1;
                for(int k=0;k<i;k++){
                    if(val1%val2==0){
                        val1=val1/val2;
                        val2=1;
                    }
                    val1*=(rowIndex-k);
                    val2*=(k+1);
                }
                r[i]=val1/val2;
                if(rowIndex-i!=i)
                    r[rowIndex-i]=r[i];
                //cout<<r[i]<<"\t";
            }
            r[rowIndex]=1;
            return r;
        }
        
        
    };

Log in to reply
 

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