2020-09-10

1、最长递增数列

public class Test5 {
    public static void main(String[] args){
        int []n = {1,7,7,8,3,6,7,2};
        System.out.println(getRes(n));
    }
    public static int getRes(int []nums){
        int len = nums.length;
        if (len < 2) return len;
        int count = 1;
        int res = 1;
        for (int i = 0; i < len - 1; i++) {
           boolean flag = false;
            while (i < len - 1 && nums[i + 1] > nums[i]) {
                count++;
                i++;
                flag = true;
            }
            res = Math.max(count, res);
            count = 1;
            if (flag) i--;
        }
        return res;
    }
}

2、最少众倍数

    public static int getRes2(int a, int b, int c, int d, int e){
        int []nums = {a, b, c, d, e};
        Arrays.sort(nums);
        int count = 0;
        for (int i = 2; i < 5; i++) {
            for (int j = 0; j <= i; j++) {
                if (nums[i] % nums[j] == 0) {
                    count++;
                }
                if (count >= 3) {
                    return nums[i];
                }
            }
            count = 0;
        }
        return -1;
    }

3、整数点在圆上

    public static int getRes3(int rSquare){
        int N = 0;
        long r = 0;
        double r_double = Math.sqrt(rSquare);
        long r_long = (long) r_double;
        double y_double = 0.0;
        long y_long = 0;
        if (r_double == r_long) {
            r = r_long - 1;
            N = N + 1;
        } else {
            r = r_long;
        }
        for (long x = 1; x <= r; x++) {
            y_double = Math.sqrt(rSquare - x * x);
            y_long = (long) y_double;
            if (y_long == y_double) {
                if (x * x + y_long * y_long == rSquare) {
                    N = N + 1;
                }
            }
        }
        return N * 4;
        //System.out.println(4 * N);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值