From 3433533b249311b3afe561c52d368af6a9f31805 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Tue, 12 Aug 2025 20:42:13 +0800 Subject: [PATCH] update --- src/8/12/3sum.cpp | 47 ++++++++++++++++++++++++++++++++ src/8/12/group-anagrams.cpp | 15 ++++++++++ src/8/12/trapping-rain-water.cpp | 34 +++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 src/8/12/3sum.cpp create mode 100644 src/8/12/group-anagrams.cpp create mode 100644 src/8/12/trapping-rain-water.cpp diff --git a/src/8/12/3sum.cpp b/src/8/12/3sum.cpp new file mode 100644 index 0000000..b04c884 --- /dev/null +++ b/src/8/12/3sum.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; + +class Solution { +public: + vector> threeSum(vector& nums) { + vector> res; + set> s; + map m; + for(int i=0;isecond>2)goto ok; + }else{ + + } + continue; + ok:; + vector 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(){ + +} \ No newline at end of file diff --git a/src/8/12/group-anagrams.cpp b/src/8/12/group-anagrams.cpp new file mode 100644 index 0000000..1286b9e --- /dev/null +++ b/src/8/12/group-anagrams.cpp @@ -0,0 +1,15 @@ +#include +#include +using namespace std; + +class Solution { +public: + vector> groupAnagrams(vector& strs) { + + } +}; + + +int main(){ + +} \ No newline at end of file diff --git a/src/8/12/trapping-rain-water.cpp b/src/8/12/trapping-rain-water.cpp new file mode 100644 index 0000000..22d83f5 --- /dev/null +++ b/src/8/12/trapping-rain-water.cpp @@ -0,0 +1,34 @@ +#include +using namespace std; + +class Solution { +public: + int trap(std::vector &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() { +} \ No newline at end of file