Why the countbits problem the leetcode oj shows runtime error but in my ide it works fine ?


  • 0
    L

    why the countbits problem the leetcode oj shows runtime error but in my ide it works fine ?

    using namespace std;
    
    class Solution {
    public:
        vector<int> countBits(int num) 
    {
            int l=0;
            vector<int>v;
            vector<int>final_array;
             for(int i=0;i<=32;i++)
           {
    
           l=pow(2,i);
           if(l>num)
           {
               // cout<<l<<endl;
               break;
           }
       }
       int start_over=0;int power=2;
       for(int i=2;i<l;i++)
       {
            if(i==pow(2,power))
           {
               power++;
               start_over=0;
           }
    
           v.push_back(v[start_over]+1);
           start_over++;
    
    
       }
       for(int i=0;i<=num;i++)
       {
           final_array.push_back(v[i]);
           
       }
       return final_array;
        
    }
     };

Log in to reply
 

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