摘要: 1779. 找到最近的有相同 X 或 Y 坐标的点 class Solution { public int nearestValidPoint(int x, int y, int[][] points) { int n = points.length; int res = (int)0x3f3f3f 阅读全文
posted @ 2022-12-01 09:00 Eiffelzero 阅读(34) 评论(0) 推荐(0)
摘要: 895. 最大频率栈 class FreqStack { Map<Integer, Stack<Integer>> stk; // k: 出现次数, v: 栈 Map<Integer, Integer> cnt; // k:数, v:该数出现的个数 int n; // 当前 个数的最大值 publi 阅读全文
posted @ 2022-11-30 09:12 Eiffelzero 阅读(25) 评论(0) 推荐(0)
摘要: 1758. 生成交替二进制字符串的最少操作数 class Solution { public int minOperations(String s) { char[] c = s.toCharArray(); int n = c.length; int res1 = 0; int res2 = 0; 阅读全文
posted @ 2022-11-29 01:09 Eiffelzero 阅读(21) 评论(0) 推荐(0)
摘要: 813. 最大平均值和的分组 题解: DP f[i][j] 表示:将[1,i]的序列分成 j 段的最大值 状态转移方程: f[i][j] = max(f[i][j], f[i][k] + (cnt[i]-cnt[k] / (i-k)) (cnt[i]-cnt[k] / (i-k)) 表示的是 最后一 阅读全文
posted @ 2022-11-28 11:15 Eiffelzero 阅读(31) 评论(0) 推荐(0)
摘要: 1752. 检查数组是否经排序和轮转得到 class Solution { public boolean check(int[] nums) { int n = nums.length; int x = 0; for(int i = 0 ; i < n - 1 ; i ++ ){ if(nums[i 阅读全文
posted @ 2022-11-27 16:04 Eiffelzero 阅读(28) 评论(0) 推荐(0)
摘要: 882. 细分图中的可到达节点 class Solution { int N = 3010, M = 20010, INF = 0x3f3f3f3f; int[] h = new int[N]; int[] e = new int[M]; int[] w = new int[M]; int[] ne 阅读全文
posted @ 2022-11-26 15:57 Eiffelzero 阅读(26) 评论(0) 推荐(0)
摘要: 809. 情感丰富的文字 class Solution { public int expressiveWords(String s, String[] words) { int res = 0; // 空字符串 if (s.isEmpty()) { // 找words中有多少个空字符串 for (S 阅读全文
posted @ 2022-11-25 22:34 Eiffelzero 阅读(21) 评论(0) 推荐(0)
摘要: 795. 区间子数组个数 题解: 实现一个函数cal 返回小于等于k的子数组数量 函数cal,可以用双指针实现 class Solution { public int numSubarrayBoundedMax(int[] nums, int left, int right) { return (i 阅读全文
posted @ 2022-11-24 19:06 Eiffelzero 阅读(22) 评论(0) 推荐(0)
摘要: 1742. 盒子中小球的最大数量 class Solution { public int countBalls(int l, int r) { int[] box = new int[50]; int max = 0; for (int i = l; i <= r; i++) { int num = 阅读全文
posted @ 2022-11-23 19:30 Eiffelzero 阅读(33) 评论(0) 推荐(0)
摘要: 878. 第 N 个神奇数字 题解:二分 + gcd 1~n中,能被a整除的个数 n/a , 能被b整除的个数 n/b, 能被a 且 b 整除的个数 n/ gcd(a,b) 则 1~n中能被a或b整除的个数为 n/a + n/b - n/gcd(a,b) 从1~n中二分,搜这个数k 1~k中 k/a 阅读全文
posted @ 2022-11-22 18:59 Eiffelzero 阅读(40) 评论(0) 推荐(0)