add codeforces solutions folder

This commit is contained in:
2026-03-05 19:55:52 +05:30
parent 77ff815f38
commit e698c35654
20 changed files with 778 additions and 0 deletions
+18
View File
@@ -0,0 +1,18 @@
class Solution{
public:
int hammingWeight(int n){
int res= 0;
/*for(int i = 0;i<32;i++){
if(n>>i && 1) res ++;
}*/
//brian-kernighan's algo
while(n){
n = n&(n-1);
res++
}
return res;
}
};
//n&n-1 resets the last set bit to 0, brian's algo takes o(number of set bits to run) unlike brute force which takes o(total no. of bits). both are o(1).