Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
698 views
in Technique[技术] by (71.8m points)

For this question of GFG . I wrote this code . But it shows segmentation fault

https://practice.geeksforgeeks.org/problems/count-total-set-bits-1587115620/1#

int Count(int n){
    int count = 0;
    while(n){
        n = n & (n - 1);
        count++;
    }
    return count;
}
int countSetBits(int n)
{
    if(n == 0)
        return 0;
    else{
        
        return Count(n) +  countSetBits(n-1);   
    }
    // Your logic here
}


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...