主要是使用 JavaScript 语言来解题,部分采用的是 C/C++。
这个仓库是具体的解题答案,若想了解一些数据结构,可以查看:wenzi0github / algorithm-by-javascript。
leetcode algorithm answer
主要是使用 JavaScript 语言来解题,部分采用的是 C/C++。
这个仓库是具体的解题答案,若想了解一些数据结构,可以查看:wenzi0github / algorithm-by-javascript。
获取所有的子集有多种方式。
前提,数组中所有的数据均不相同。
https://leetcode.cn/problems/subsets/
class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
vector<int> temp;
vector<vector<int>> result;
int i, j, size, resSize;
size = (int)nums.size();
result.push_back(temp);
for(i=0; i<size; i++)
{
for(j=0, resSize=(int)result.size(); j<resSize; j++)
{
vector<int> temp1 = result[j];
temp1.push_back(nums[i]);
result.push_back(temp1);
}
}
return result;
}
};
class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
vector<int> temp;
vector<vector<int>> result;
find(nums, 0, temp, result);
return result;
}
private:
int find(vector<int>& nums, int curIndex, vector<int>& temp, vector<vector<int>>& result)
{
if (curIndex >= nums.size())
{
result.push_back(temp);
return 0;
}
// 每个当前的数字,都有使用和不使用两种选择
// 不使用该数字
find(nums, curIndex+1, temp, result);
// 使用该数字
vector<int> needTemp = temp;
needTemp.push_back(nums[curIndex]);
find(nums, curIndex+1, needTemp, result);
return 0;
}
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.