Skip to content

Commit baacf2f

Browse files
add 78
1 parent d136360 commit baacf2f

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ LeetCode
3838
|0075|[Sort Colors](https://leetcode.com/problems/sort-colors/) | c | [c++](./src/0075-Sort-Colors/0075.cpp) |[python](./src/0075-Sort-Colors/0075.py)|||Medium|
3939
|0076|[Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/) | c | [c++](./src/0076-Minimum-Window-Substring/0076.cpp) |[python](./src/0076-Minimum-Window-Substring/0076.py)|||Easy|
4040
|0077|[Combinations](https://leetcode.com/problems/combinations/) | c | [c++](./src/0077-Combinations/0077.cpp) |[python](./src/0077-Combinations/0077.py)|||Medium|
41+
|0078|[Subsets](https://leetcode.com/problems/subsets/) | c | [c++](./src/0078-Subsets/0078.cpp) |[python](./src/0078-Subsets/0078.py)|||Medium|
4142
|0080|[Remove Duplicates from Sorted Array II](https://leetcode.com/problems/remove-duplicates-from-sorted-array-ii/) | c | [c++]() |[python](./src/0080-Remove-Duplicates-from-Sorted-Array-II/0080.py)|||Medium|
4243
|0082|[Remove Duplicates from Sorted List II](https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/) | c | [c++](./src/0082-Remove-Duplicates-from-Sorted-List-II/0082.cpp) |[python](./src/0082-Remove-Duplicates-from-Sorted-List-II/0082.py)|||Medium|
4344
|0083|[Remove Duplicates from Sorted List](https://leetcode.com/problems/remove-duplicates-from-sorted-list/) | c | [c++](./src/0083-Remove-Duplicates-from-Sorted-List/0083.cpp) |[python](./src/0083-Remove-Duplicates-from-Sorted-List/0083.py)|||Easy|

src/0078-Subsets/0078.cpp

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <iostream>
2+
#include <string>
3+
#include <vector>
4+
#include <math.h>
5+
using namespace std;
6+
7+
static int x = []() {std::ios::sync_with_stdio(false); cin.tie(0); return 0; }();
8+
class Solution
9+
{
10+
public:
11+
vector<vector<int>> subsets(vector<int>& nums)
12+
{
13+
vector<vector<int>> result;
14+
int n = pow(2, nums.size());
15+
for (int i = 0; i < n; i++)
16+
{
17+
vector<int> tmp;
18+
for (unsigned int j = 0; j < nums.size(); j++)
19+
if(i >> j & 1) tmp.push_back(nums[j]);
20+
result.push_back(tmp);
21+
}
22+
return result;
23+
}
24+
};

src/0078-Subsets/0078.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Solution:
2+
def subsets(self, nums):
3+
"""
4+
:type nums: List[int]
5+
:rtype: List[List[int]]
6+
"""
7+
if not nums:
8+
return [[]]
9+
result = self.subsets(nums[1:])
10+
return result + [[nums[0]] + s for s in result]
11+
12+
13+
if __name__ == '__main__':
14+
nums = [1, 2, 3]
15+
print(Solution().subsets(nums))

0 commit comments

Comments
 (0)