MCPcopy Create free account
hub / github.com/codedecks-in/LeetCode-Solutions / helper

Method helper

Java/Perm_Recus.java:7–25  ·  view source on GitHub ↗
(int start, int[] nums, List<List<Integer>> result)

Source from the content-addressed store, hash-verified

5}
6
7private void helper(int start, int[] nums, List<List<Integer>> result)
8{
9 if(start==nums.length-1){
10 ArrayList<Integer> list = new ArrayList<>(); //if starting value(say n) is the last value , this will make a new list with the values and the new starting value is n
11 for(int num: nums)
12 {
13 list.add(num);
14 }
15 result.add(list);
16 return;
17 }
18
19 for(int i=start; i<nums.length; i++) //a loop to keep on swapping as many times as there are values in the list
20 {
21 swap(nums, i, start);
22 helper(start+1, nums, result);
23 swap(nums, i, start);
24 }
25}
26
27private void swap(int[] nums, int i, int j)
28{

Callers 1

permuteMethod · 0.45

Calls 2

swapMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected