Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int numSubseq(vector<int>& nums, int target) {
- sort(nums.begin(), nums.end());
- int ans=0;
- int pow[nums.size()], mod=int(1e9)+7;
- pow[0] = 1;
- for(int i=1; i<nums.size(); i++)
- pow[i] = (pow[i-1]*2LL)%mod;
- int left=0, right=nums.size()-1;
- while(left <= right){
- if(nums[left] + nums[right] > target)
- right--;
- else
- ans = (ans+pow[right-left++])%mod;
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement