public static List<List<Integer>> permute(int[] nums) {
List<List<Integer>> res = new ArrayList<>();
dfsBacktrackingAllSubsets(nums, 0, new ArrayList<>(), res);
return res;
}
private static void dfsBacktrackingAllSubsets(int[] nums, int index, List<Integer> prevCombination, List<List<Integer>> allCombinations) {
List<Integer> newCombination = new ArrayList<>(prevCombination);
newCombination.add(nums[index]);
allCombinations.add(newCombination);
if (index == nums.length - 1) {
return;
}
dfsBacktrackingAllSubsets(nums, index + 1, prevCombination, allCombinations);
dfsBacktrackingAllSubsets(nums, index + 1, newCombination, allCombinations);
}
-
MY PROJECTS
-
Recent Posts
- Java.Multithreading.Why might a private mutex be needed?
- Java.Multithreading.Can new instances of a class be created while a static synchronized method is executing?
- Java.Multithreding.What states can a thread be in?
- Java.Multithreading.Example with consumer and producer
- Java.Multithreading.When to use what ?
- Java.Multithreading.What are the different types of synchronization in Java?
- Java.Multithreading.Define the concept of “synchronization”.
- Java.Multithreading.if you say monitor is the mutex, tell me in terms of mutex how sync happens ?
- Java.Multithreading.Give me details about monitor, i cannot understand how it can synchronize only part of the method if we locking whole the object ?
- Java.Multithreading.Why do we need Synchronized (this) and Synchronized method if they give us the same result ?
- Java.Multithreading.What is a “monitor” in Java?
- Java.Multithreading.How can a thread be started forcibly?
- Java.Multithreading.What is the difference between start() and run() methods in Thread?
- Java.Multithreading.What is the difference between Thread and Runnable?
- Java.Multithreading.How can a thread be created?
- Java.Multithreading.What are “green threads” and do they exist in Java?
- Java.Multithreading.What is the difference between a process and a thread?
- Java.Multithreading.What is ordering, as-if-serial semantics, sequential consistency, visibility, atomicity, happens-before, mutual exclusion, safe publication?
- Java.Multithreading.What is “cooperative multitasking”? What type of multitasking does Java use? What is the reason for this choice?
- Java.Multithreading.Can i adjust ThreadPoolExeccutor to work on different cores ?
Categories
- Aptana
- Azure
- C#
- DataSnap
- DBExpress
- Delphi
- Delphi и сети
- Delphi. Язык программирования
- ExtJS
- FastReport
- FireDAC
- FireMonkey
- GIT
- ICS
- IDE
- IIS
- Indy
- InnoSetup
- javascript
- jQuery
- JSON
- LiveBindings
- MSHTML
- MySQL
- PHP
- REST
- Ribbons
- SMS
- SQL инструкции
- SVN
- TRichView
- UniGui
- WebBroker
- WinAPI
- Windows
- Алгоритмы
- Без рубрики
- Деревья
- Ищу ответ
- Компонентостроение
- Мои компоненты
- Начальный уровень
- Обработка исключений
- Парсинг
- Потоки(Threads)
- Регулярные выражения
- Тестирование приложений