Wrong Answer - Part of 1st Solution accepted by Judge


  • 0
    A
    class Solution {
    
      public:
    
       vector<int> getRow(int rowIndex) {
        
        long temp , prev,i;
        vector<int> v;
        if(rowIndex<0)
            return v;
            
        prev = 1;
        v.push_back(prev);
        
        for(int i=1;i<=rowIndex;i++){
            int t = (v[i-1] * (rowIndex-i+1))/(i);
            v.push_back(t);
        }
        
        return v;
    }
     };
    
    
         Same Solution is used for generating each row in the Problem Pascals triangle I is accepted but this 
         is giving wrong answer for n = 30

  • 0
    D

    Be careful about integer overflow. You need to convert the result of the multiplication to (long long). I noticed this when I saw the output it gave compared to mine. Index 15 or 16 is a negative number due to overflow.


Log in to reply
 

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