leetcode 2021 春赛学习勋章2021 春赛题集(day1)

LCP 28. 采购方案

简单题重拳出击

class Solution {
    public int purchasePlans(int[] nums, int target) {
        int ans = 0;
        int mod = 1000000007;
        Arrays.sort(nums);
        int n = nums.length;
        int l = 0, r = n - 1;
        while(l < r){
            int sum = nums[l] + nums[r];
            if(sum <= target){
                ans += r - l;
                l ++;
            }else{
                r --;
            }
            ans %= mod; 
        }
        return ans % mod;
    }
}

LCP 29. 乐团站位

不太会的中等题 cv题解

class Solution {
    public int orchestraLayout(int num, int x, int y) {
        long circle = Math.min(Math.min(x,num-1-x), Math.min(y,num-1-y));
        long len = num-1-2*circle;
        long count = (long)num*num - (len+1)*(len+1);

        if(x == circle && y < num-1-circle){
            count += y - circle + 1;         
        }else if(y == num-1-circle && x < num-1-circle){
            count += len + x-circle+1;       
        }else if(x == num-1-circle && y>circle){
            count += 2*len + num-circle-y;   
        }else{
            count += 3*len + num-circle-x;
        }

        return (int)(count%9==0?9:count%9);
    }
}

 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值