mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-12-21 14:41:45 +00:00
Compare commits
No commits in common. "d66152a01b9aa507ca986fb9760d050d6579d059" and "50a8547e704ffefce2563d49da4809ceb5b8f6e3" have entirely different histories.
d66152a01b
...
50a8547e70
@ -1,47 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <cstdint>
|
|
||||||
#include <functional>
|
|
||||||
#include <iostream>
|
|
||||||
#include <map>
|
|
||||||
#include <set>
|
|
||||||
#include <tuple>
|
|
||||||
#include <unordered_set>
|
|
||||||
#include <vector>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Solution {
|
|
||||||
public:
|
|
||||||
vector<vector<int>> threeSum(vector<int>& nums) {
|
|
||||||
vector<vector<int>> res;
|
|
||||||
set<vector<int>> s;
|
|
||||||
map<int,int> m;
|
|
||||||
for(int i=0;i<nums.size();i++){
|
|
||||||
m[nums[i]]++;
|
|
||||||
}
|
|
||||||
for(int i=0;i<nums.size();i++){
|
|
||||||
for(int j=i+1;j<nums.size();j++){
|
|
||||||
if(auto p =m.find(-(nums[i]+nums[j]));p!=m.end()){
|
|
||||||
if(nums[i]==nums[j]){
|
|
||||||
auto p = m.find(nums[i]);
|
|
||||||
if(p->second>2)goto ok;
|
|
||||||
}else{
|
|
||||||
|
|
||||||
}
|
|
||||||
continue;
|
|
||||||
ok:;
|
|
||||||
vector<int> nn={nums[i],nums[j],-(nums[i]+nums[j])};
|
|
||||||
sort(nn.begin(),nn.end());
|
|
||||||
if(s.find(nn)==s.end()){
|
|
||||||
res.push_back(nn);
|
|
||||||
s.insert(nn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
#include <algorithm>
|
|
||||||
#include <unordered_map>
|
|
||||||
#include <utility>
|
|
||||||
#include<vector>
|
|
||||||
#include<string>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Solution {
|
|
||||||
public:
|
|
||||||
vector<vector<string>> groupAnagrams(vector<string>& strs) {
|
|
||||||
unordered_map<string, vector<string>> m;
|
|
||||||
for(int i=0;i<strs.size();i++){
|
|
||||||
string ns=strs[i];
|
|
||||||
sort(ns.begin(),ns.end());
|
|
||||||
m[ns].push_back(std::move(strs[i]));
|
|
||||||
}
|
|
||||||
vector<vector<string>> ans;
|
|
||||||
for(auto &s :m){
|
|
||||||
ans.push_back(std::move(s.second));
|
|
||||||
}
|
|
||||||
return ans;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,34 +0,0 @@
|
|||||||
#include <vector>
|
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class Solution {
|
|
||||||
public:
|
|
||||||
int trap(std::vector<int> &height) {
|
|
||||||
|
|
||||||
if (height.size() < 3) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
int n = height.size();
|
|
||||||
int l = 0, r = n - 1;
|
|
||||||
|
|
||||||
int lmax = 0;
|
|
||||||
int rmax = 0;
|
|
||||||
|
|
||||||
long long totw = 0;
|
|
||||||
while (l < r) {
|
|
||||||
lmax = std::max(lmax, height[l]);
|
|
||||||
rmax = std::max(rmax, height[r]);
|
|
||||||
if (lmax < rmax) {
|
|
||||||
totw += lmax - height[l];
|
|
||||||
l++;
|
|
||||||
} else {
|
|
||||||
totw += rmax - height[r];
|
|
||||||
r--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return totw;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user