Skip to content

Commit e33a894

Browse files
committed
add 78, 461, 2044, 2413
1 parent a2e9728 commit e33a894

4 files changed

+70
-0
lines changed

0078-subsets.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
"""
2+
78. Subsets
3+
4+
Submitted: January 20, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
NenirtL 17.74 MB (beats 53.75%)
8+
"""
9+
10+
class Solution:
11+
def subsets(self, nums: List[int]) -> List[List[int]]:
12+
# https://docs.python.org/3/library/itertools.html#itertools-recipes, powerset
13+
return list(chain.from_iterable(combinations(nums, r) for r in range(len(nums)+1)))

0461-hamming-distance.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
461. Hamming Distance
3+
4+
Submitted; January 20, 2025
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 8.00 MB (beats 5.85%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
int hammingDistance(int x, int y) {
13+
int result = 0;
14+
while (x != 0 && y != 0) {
15+
if ((x & 1) != (y & 1)) ++result;
16+
x >>= 1;
17+
y >>= 1;
18+
}
19+
if (y != 0) swap(x, y);
20+
while (x != 0) {
21+
result += (x & 1);
22+
x >>= 1;
23+
}
24+
return result;
25+
}
26+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
"""
2+
2044. Count Number of Maximum Bitwise-OR Subsets
3+
4+
Submitted: January 20, 2025
5+
6+
Runtime: 796 MB (beats 23.50%)
7+
Memory: 17.93 MB (beats 36.21%)
8+
"""
9+
10+
class Solution:
11+
def countMaxOrSubsets(self, nums: List[int]) -> int:
12+
# derived from https://docs.python.org/3/library/itertools.html#itertools-recipes, powerset
13+
max_or = reduce((lambda x, y: x | y), nums, 0)
14+
return sum(
15+
reduce((lambda x, y: x | y), it, 0) == max_or for it in chain.from_iterable(combinations(nums, r) for r in range(len(nums)+1))
16+
)

2413-smallest-even-multiple.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
2413. Smallest Even Multiple
3+
4+
Submitted: January 20, 2925
5+
6+
Runtime: 0 ms (beats 100.00%)
7+
Memory: 7.91 MB (beats 25.99%)
8+
*/
9+
10+
class Solution {
11+
public:
12+
int smallestEvenMultiple(int n) {
13+
return n & 1 ? n << 1 : n;
14+
}
15+
};

0 commit comments

Comments
 (0)