[Solved]An interesting regular pattern with C++


  • 1
    L

    `
    class Solution {

    public:

    vector<int> countBits(int num) {
        vector<int> res;
        res.push_back(0);
        if(num==0)
            return res;
        res.push_back(1);
        int count = 2;
        while(count<=num){
            res.push_back(res[count/2]+res[count%2]);
            count++;
        }
        return res;
    }
    

    };`


Log in to reply
 

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