0
点赞
收藏
分享

微信扫一扫

LeetCode刷题计划Day17

78. 子集

class Solution {
    public List<List<Integer>> subsets(int[] nums) {        List<Integer> path = new ArrayList<>();        List<List<Integer>> res = new ArrayList<>();       dfs(nums, path, res, 0);        return res;    }    private void dfs(int[] nums, List<Integer> path, List<List<Integer>> res, int start) {        res.add(new ArrayList<Integer>(path));        for(int i = start; i < nums.length; i ++) {            path.add(nums[i]);            dfs(nums, path, res, i+1);            path.remove(path.size() - 1);        }    }}

470. 用Rand7()实现Rand10()

class Solution extends SolBase {
    public int rand10() {
        int ans = 0;
        do {
            int x = rand7();
            int y = rand7();
            ans = (x - 1) * 7 + (y - 1);
        } while (ans >= 40);
        return 1 + ans % 10;
    }

}
举报

相关推荐

0 条评论