diff options
author | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2025-06-27 12:23:02 -0600 |
commit | a96b65cbfad7f62f3db6b2eab105e4e25c0414c5 (patch) | |
tree | e2a2b3f49f9fb741be81415266ac93e74cff42ec /other/num_subseq_satisfy.cpp | |
parent | 694ad5ed71edcb1deccab54b72d706b779918276 (diff) | |
download | leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.tar.gz leetcode-a96b65cbfad7f62f3db6b2eab105e4e25c0414c5.zip |
chore: remove old cpp and rust solutions
Diffstat (limited to 'other/num_subseq_satisfy.cpp')
-rw-r--r-- | other/num_subseq_satisfy.cpp | 34 |
1 files changed, 0 insertions, 34 deletions
diff --git a/other/num_subseq_satisfy.cpp b/other/num_subseq_satisfy.cpp deleted file mode 100644 index 6eb1a12..0000000 --- a/other/num_subseq_satisfy.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// 1498. Number of Subsequences That Satisfy the Given Sum Condition -#include "leetcode.h" - -/* - * given an array of integers 'nums' and an integer 'target' - * return the numbe of non-empty subsequences of 'nums' such - * that the sum of the minimum and maximum element on it is - * less or equal to 'target'. return modulo 10^9+7 - */ - -class Solution { -public: - int numSubSeq(vector<int> &nums, int target) { - int ans = 0, mod = 1000000007; - vector<int> pre = {0, 1}; - for (auto i = pre.size(); i <= nums.size(); ++i) - pre.push_back((pre.back() << 1) % mod); - sort(nums.begin(), nums.end()); - for (int i = 0, j = nums.size() - 1; i <= j; ++i) { - while (i <= j && nums[i] + nums[j] > target) - --j; - ans = (ans + pre[j - i + 1]) % mod; - } - return ans; - } -}; - -int main() { - Solution obj; - vector<int> n1 = {3, 5, 6, 7}, n2 = {3, 3, 6, 8}, n3 = {2, 3, 3, 4, 6, 7}; - printf("%d\n", obj.numSubSeq(n1, 9)); // expect: 4 - printf("%d\n", obj.numSubSeq(n2, 10)); // expect: 6 - printf("%d\n", obj.numSubSeq(n3, 12)); // expect: 61 -} |