-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay37
59 lines (34 loc) · 1.05 KB
/
Day37
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//#Day37 of My #100DaysOfCodingChallenge: Exploring Bitmanipulation!
//Problem Solved : Swap two numbers
//Problem Link : https://www.geeksforgeeks.org/problems/swap-two-numbers3844/1
//Problem Solved : Count total set bits
//Problem Link : https://www.geeksforgeeks.org/problems/count-total-set-bits-1587115620/1
class Solution{
static List<Integer> get(int a,int b)
{
// code here
List<Integer>demo = new ArrayList<>();
a= a^b;
b= a^b;
a= a^b;
demo.add(a);
demo.add(b);
return demo;
}
}
class Solution{
//Function to return sum of count of set bits in the integers from 1 to n.
public static int countSetBits(int n){
int count = 0;
for (int i = 1; i <= n; i++) {
int num = i;
while (num > 0) {
if ((num & 1) == 1) {
count++;
}
num >>= 1;
}
}
return count;
}
}