mirror of
https://github.com/Manoj-HV30/dsa-competitive-programming.git
synced 2026-05-16 19:35:22 +00:00
leetcode new problems
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
class Solution {
|
||||
public:
|
||||
vector<vector<int>> fourSum(vector<int>& nums, int target) {
|
||||
int n = nums.size();
|
||||
sort(nums.begin(), nums.end());
|
||||
set<vector<int>> set;
|
||||
vector<vector<int>> output;
|
||||
for(int i=0; i<n-3; i++){
|
||||
for(int j=i+1; j<n-2; j++){
|
||||
for(int k=j+1; k<n-1; k++){
|
||||
for(int l=k+1; l<n; l++){
|
||||
if((long long)nums[i] + (long long)nums[j] + (long long)nums[k] +
|
||||
(long long)nums[l] == target){
|
||||
set.insert({nums[i], nums[j], nums[k], nums[l]});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(auto it : set){
|
||||
output.push_back(it);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
};
|
||||
|
||||
// TC : O(n^4)
|
||||
// SC : O(n)
|
||||
Reference in New Issue
Block a user