第九周

第九周

博弈论:

leetcode:1025:

public class Solution {
    public boolean divisorGame(int N) {
        //博弈论,最终是偶数的话就会赢
        return (N&1)==0;
    }
}

leetcode:319:

public class Solution2 {
    public static int bulbSwitch(int n) {
        //最后发现规律:结果为开根号
        return (int) Math.sqrt(n);
    }
}

leetcode:326

public class Solution2 {
    public boolean isPowerOfThree(int n) {
        //3^19=1162261467,只要是3的次幂就可以被n整除
        return n>0&&1162261467%n==0;
    }
}

leetcode:172

class Solution {
    public int trailingZeroes(int n) {
        //题目要求logn,所以使用递归
        //0的个数就是2*5的对数,但是像25是两个5,所直接递归
        return n==0?0:n/5+trailingZeroes(n/5);
    }
}

leetcode:292

public boolean canWinNim(int n) {
        //寻找规律,当我们面对n是4的倍数时就一定会输,反正就会赢
        return n%4!=0;//不是4的倍数就赢
    }

leetcode:877

public boolean stoneGame(int[] piles) {
        //你会发现,因为亚历克斯先选,最优解总是他比较多
        return true;
    }

笔记:在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值