diff --git a/25/12/944.cpp b/25/12/944.cpp new file mode 100644 index 0000000..e2c8488 --- /dev/null +++ b/25/12/944.cpp @@ -0,0 +1,18 @@ +#include +#include + +class Solution { +public: + int minDeletionSize(std::vector& strs) { + int ans = 0; + for(int i = 0;i + +class Solution { +public: + int minOperations(std::vector& nums) { + std::unordered_map m; + int count = 0; + for(auto num: nums){ + m[num] ++; + if (m[num] > 1) { + count++; + } + } + if(count == 0){ + return 0; + } + int ans = 0; + for (int i = 0; i 1) { + m[nums[i]]--; + count--; + } + if ((i + 1) % 3 == 0) { + ans++; + } + if (count == 0) { + if ((i + 1) % 3 != 0) { + ans++; + } + break; + } + } + return ans; + } +}; \ No newline at end of file diff --git a/25/12/comp/20q2.cpp b/25/12/comp/20q2.cpp new file mode 100644 index 0000000..2941350 --- /dev/null +++ b/25/12/comp/20q2.cpp @@ -0,0 +1,25 @@ +#include +#include +#include +#include + +class Solution { +public: + int maximumSum(std::vector &nums) { + int n = nums.size(); + int ans = 0; + std::vector b[3]; + for (auto num : nums) + b[num % 3].push_back(num); + for (int i = 0; i < 3; i++) { + std::sort(b[i].begin(), b[i].end(), [](int a, int b) { return a > b; }); + if (b[i].size() >= 3) { + ans = std::max(std::reduce(b[i].begin(), b[i].begin() + 3), ans); + } + } + if (b[0].size() && b[1].size() && b[2].size()) { + ans = std::max(ans, b[0][0] + b[1][0] + b[2][0]); + } + return ans; + } +}; \ No newline at end of file