diff options
author | Jack Sangdahl <jack@pngu.org> | 2025-03-10 00:36:13 -0600 |
---|---|---|
committer | Jack Sangdahl <jack@pngu.org> | 2025-03-10 00:36:13 -0600 |
commit | 7c60dee83b436e8e8a667bf9f191beced8de4fc3 (patch) | |
tree | eb7a24ee2067f92245c57bb118e85a1baf15df50 /pairs_spells_potions.cpp | |
parent | 5d7cdc215e4ba1ec4cbb24c084cccb5e5e641468 (diff) | |
download | leetcode-master.tar.gz leetcode-master.zip |
Diffstat (limited to 'pairs_spells_potions.cpp')
-rw-r--r-- | pairs_spells_potions.cpp | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/pairs_spells_potions.cpp b/pairs_spells_potions.cpp deleted file mode 100644 index 255b4a0..0000000 --- a/pairs_spells_potions.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// 2300. Successful Pairs of Spells and Potions -#include "leetcode.h" - -/* - * given two positive integer arrays 'spells' and 'potions', of length n and m - * respectively where 'spells[i]' represents the strength of the i'th spell and - * 'potions[j] represents the strength of the j'th potion. also given an integer - * success. a spell and potion pair is considered successful if the product of - * their strengths is at least 'success'. return an integer array 'pairs' of - * lengthn where 'pairs[i]' is the number of potions that will form a successful - * pair with the i'th spell. - */ - -class Solution { -public: - vector<int> successfulPairs(vector<int> &spells, vector<int> &potions, - long long success) { - int m = potions.size(); - vector<int> ans; - sort(potions.begin(), potions.end()); - for (auto i : spells) { - int left = 0, right = m - 1, mid; - while (left <= right) { - mid = (left + right) >> 1; - if ((long long)i * potions[mid] >= success) - right = mid - 1; - else - left = mid + 1; - } - ans.push_back(m - left); - } - return ans; - } -}; - -int main() { - Solution obj; - vector<int> s1 = {5, 1, 3}, s2 = {3, 1, 2}; - vector<int> p1 = {1, 2, 4, 4, 5}, p2 = {8, 5, 8}; - for (auto i : obj.successfulPairs(s1, p1, 7)) - printf("%d ", i); // expec: 4 0 3 - printf("\n"); - for (auto i : obj.successfulPairs(s2, p2, 16)) - printf("%d ", i); // expec: 2 0 2 -} |