0
点赞
收藏
分享

微信扫一扫

【采购方案(lcp-28-java)】

花明 2022-01-17 阅读 32

采购方案(lcp-28-java)

public class LC247_lcp_28_purchasePlans {
    //排序
    public static int purchasePlans(int[] nums, int target) {
        Arrays.sort(nums);
        int left = 0, right = nums.length - 1, ans = 0;
        while (left < right) {
            if (nums[left] + nums[right] <= target) {
                ans += right - left;
                left++;
            } else {
                right--;
            }
            ans %= 1000000007;
        }
        return ans %= 1000000007;
    }

    public static void main(String[] args) {
        System.out.println(purchasePlans(new int[]{2, 5, 3, 5}, 6));
    }
}
举报

相关推荐

0 条评论