0
点赞
收藏
分享

微信扫一扫

LeetCode第290场周赛

其生 2022-04-24 阅读 155

文章目录


6041. 多个数组求交集

题目描述

  • 6041. 多个数组求交集

在这里插入图片描述

在这里插入图片描述

哈希

class Solution {
    public List<Integer> intersection(int[][] nums) {
        int n = nums.length;
        int[] freq = new int[1001];
        List<Integer> res = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < nums[i].length; j++) {
                freq[nums[i][j]]++;
            }
        }
        for (int i = 1; i <= 1000; i++) {
            if (freq[i] >= n) {
                res.add(i);
            }
        }
        return res;
    }
}

6042. 统计圆内格点数目

题目描述

  • 6042. 统计圆内格点数目

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

枚举

枚举 200 × 200 200 \times 200 200×200范围内的所有点,并判断是否在某一个圆内

class Solution {
    public int countLatticePoints(int[][] circles) {
        int cnt = 0;
        for (int nx = 0; nx <= 200; nx++) {
            for (int ny = 0; ny <= 200; ny++) {
                for (int[] c : circles) {
                    int x = c[0], y = c[1], r = c[2];
                    if (isInCircle(x, y, r, nx, ny)) {
                        cnt++;
                        break;
                    }
                }
            }
        }
        return cnt;
    }
    private boolean isInCircle(int x, int y, int r, int nx, int ny) {
        return Math.pow(nx - x, 2) + Math.pow(ny - y, 2) <= Math.pow(r, 2);
    }
}

6043. 统计包含每个点的矩形数目

  • 6043. 统计包含每个点的矩形数目

6044. 花期内花的数目

  • 6044. 花期内花的数目
举报

相关推荐

0 条评论