联想校园招聘笔试题

编程语言 · 历年真题改编 · 题号 23322
单选题编程语言难度 3真题改编 · 2024中大厂

题目

实现一个函数,返回整数数组中所有唯一组合。假设数组中元素无重复。 import java.util.*; public class UniqueCombinations { public static List<List<Integer>> combine(int[] nums) { List<List<Integer>> result = new ArrayList<>(); backtrack(result, new ArrayList<>(), nums, 0); return result; } private static void backtrack(List<List<Integer>> result, List<Integer> tempList, int[] nums, int start) { result.add(new ArrayList<>(tempList)); for (int i = start; i < nums.length; i++) { ____ // 填空 backtrack(result, tempList, nums, i + 1); tempList.remove(tempList.size() - 1); } } public static void main(String[] args) { int[] nums = {1, 2, 3}; List<List<Integer>> combinations = combine(nums); for (List<Integer> combination : combinations) { System.out.println(combination); } } } 填空内容是:

选项4 个

AtempList.add(nums[i])
Bnums[i] > 0
CCollections.addAll(tempList, nums[i])
DtempList.contains(nums[i])
🔒 答案与解析:登录后可查看本题答案、解析与考点讲解,并可在线作答自动判分 登录 / 注册
‹ 上一题 返回公务员考试·行测真题 下一题 ›

同类型题目编程语言 · 继续练习

题目免费浏览 · 整套练习与模拟考登录后开始 · 答案与解析登录后可见