mirror of
https://github.com/krahets/hello-algo.git
synced 2026-04-13 18:00:18 +08:00
translation: Add Python and Java code for EN version (#1345)
* Add the intial translation of code of all the languages * test * revert * Remove * Add Python and Java code for EN version
This commit is contained in:
77
en/codes/java/chapter_backtracking/n_queens.java
Normal file
77
en/codes/java/chapter_backtracking/n_queens.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* File: n_queens.java
|
||||
* Created Time: 2023-05-04
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class n_queens {
|
||||
/* Backtracking algorithm: n queens */
|
||||
public static void backtrack(int row, int n, List<List<String>> state, List<List<List<String>>> res,
|
||||
boolean[] cols, boolean[] diags1, boolean[] diags2) {
|
||||
// When all rows are placed, record the solution
|
||||
if (row == n) {
|
||||
List<List<String>> copyState = new ArrayList<>();
|
||||
for (List<String> sRow : state) {
|
||||
copyState.add(new ArrayList<>(sRow));
|
||||
}
|
||||
res.add(copyState);
|
||||
return;
|
||||
}
|
||||
// Traverse all columns
|
||||
for (int col = 0; col < n; col++) {
|
||||
// Calculate the main and minor diagonals corresponding to the cell
|
||||
int diag1 = row - col + n - 1;
|
||||
int diag2 = row + col;
|
||||
// Pruning: do not allow queens on the column, main diagonal, or minor diagonal of the cell
|
||||
if (!cols[col] && !diags1[diag1] && !diags2[diag2]) {
|
||||
// Attempt: place the queen in the cell
|
||||
state.get(row).set(col, "Q");
|
||||
cols[col] = diags1[diag1] = diags2[diag2] = true;
|
||||
// Place the next row
|
||||
backtrack(row + 1, n, state, res, cols, diags1, diags2);
|
||||
// Retract: restore the cell to an empty spot
|
||||
state.get(row).set(col, "#");
|
||||
cols[col] = diags1[diag1] = diags2[diag2] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Solve n queens */
|
||||
public static List<List<List<String>>> nQueens(int n) {
|
||||
// Initialize an n*n size chessboard, where 'Q' represents the queen and '#' represents an empty spot
|
||||
List<List<String>> state = new ArrayList<>();
|
||||
for (int i = 0; i < n; i++) {
|
||||
List<String> row = new ArrayList<>();
|
||||
for (int j = 0; j < n; j++) {
|
||||
row.add("#");
|
||||
}
|
||||
state.add(row);
|
||||
}
|
||||
boolean[] cols = new boolean[n]; // Record columns with queens
|
||||
boolean[] diags1 = new boolean[2 * n - 1]; // Record main diagonals with queens
|
||||
boolean[] diags2 = new boolean[2 * n - 1]; // Record minor diagonals with queens
|
||||
List<List<List<String>>> res = new ArrayList<>();
|
||||
|
||||
backtrack(0, n, state, res, cols, diags1, diags2);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int n = 4;
|
||||
List<List<List<String>>> res = nQueens(n);
|
||||
|
||||
System.out.println("Input the dimensions of the chessboard as " + n);
|
||||
System.out.println("Total number of queen placement solutions = " + res.size());
|
||||
for (List<List<String>> state : res) {
|
||||
System.out.println("--------------------");
|
||||
for (List<String> row : state) {
|
||||
System.out.println(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
51
en/codes/java/chapter_backtracking/permutations_i.java
Normal file
51
en/codes/java/chapter_backtracking/permutations_i.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/**
|
||||
* File: permutations_i.java
|
||||
* Created Time: 2023-04-24
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class permutations_i {
|
||||
/* Backtracking algorithm: Permutation I */
|
||||
public static void backtrack(List<Integer> state, int[] choices, boolean[] selected, List<List<Integer>> res) {
|
||||
// When the state length equals the number of elements, record the solution
|
||||
if (state.size() == choices.length) {
|
||||
res.add(new ArrayList<Integer>(state));
|
||||
return;
|
||||
}
|
||||
// Traverse all choices
|
||||
for (int i = 0; i < choices.length; i++) {
|
||||
int choice = choices[i];
|
||||
// Pruning: do not allow repeated selection of elements
|
||||
if (!selected[i]) {
|
||||
// Attempt: make a choice, update the state
|
||||
selected[i] = true;
|
||||
state.add(choice);
|
||||
// Proceed to the next round of selection
|
||||
backtrack(state, choices, selected, res);
|
||||
// Retract: undo the choice, restore to the previous state
|
||||
selected[i] = false;
|
||||
state.remove(state.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Permutation I */
|
||||
static List<List<Integer>> permutationsI(int[] nums) {
|
||||
List<List<Integer>> res = new ArrayList<List<Integer>>();
|
||||
backtrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] nums = { 1, 2, 3 };
|
||||
|
||||
List<List<Integer>> res = permutationsI(nums);
|
||||
|
||||
System.out.println("Input array nums = " + Arrays.toString(nums));
|
||||
System.out.println("All permutations res = " + res);
|
||||
}
|
||||
}
|
||||
53
en/codes/java/chapter_backtracking/permutations_ii.java
Normal file
53
en/codes/java/chapter_backtracking/permutations_ii.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* File: permutations_ii.java
|
||||
* Created Time: 2023-04-24
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class permutations_ii {
|
||||
/* Backtracking algorithm: Permutation II */
|
||||
static void backtrack(List<Integer> state, int[] choices, boolean[] selected, List<List<Integer>> res) {
|
||||
// When the state length equals the number of elements, record the solution
|
||||
if (state.size() == choices.length) {
|
||||
res.add(new ArrayList<Integer>(state));
|
||||
return;
|
||||
}
|
||||
// Traverse all choices
|
||||
Set<Integer> duplicated = new HashSet<Integer>();
|
||||
for (int i = 0; i < choices.length; i++) {
|
||||
int choice = choices[i];
|
||||
// Pruning: do not allow repeated selection of elements and do not allow repeated selection of equal elements
|
||||
if (!selected[i] && !duplicated.contains(choice)) {
|
||||
// Attempt: make a choice, update the state
|
||||
duplicated.add(choice); // Record selected element values
|
||||
selected[i] = true;
|
||||
state.add(choice);
|
||||
// Proceed to the next round of selection
|
||||
backtrack(state, choices, selected, res);
|
||||
// Retract: undo the choice, restore to the previous state
|
||||
selected[i] = false;
|
||||
state.remove(state.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Permutation II */
|
||||
static List<List<Integer>> permutationsII(int[] nums) {
|
||||
List<List<Integer>> res = new ArrayList<List<Integer>>();
|
||||
backtrack(new ArrayList<Integer>(), nums, new boolean[nums.length], res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] nums = { 1, 2, 2 };
|
||||
|
||||
List<List<Integer>> res = permutationsII(nums);
|
||||
|
||||
System.out.println("Input array nums = " + Arrays.toString(nums));
|
||||
System.out.println("All permutations res = " + res);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* File: preorder_traversal_i_compact.java
|
||||
* Created Time: 2023-04-16
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class preorder_traversal_i_compact {
|
||||
static List<TreeNode> res;
|
||||
|
||||
/* Pre-order traversal: Example one */
|
||||
static void preOrder(TreeNode root) {
|
||||
if (root == null) {
|
||||
return;
|
||||
}
|
||||
if (root.val == 7) {
|
||||
// Record solution
|
||||
res.add(root);
|
||||
}
|
||||
preOrder(root.left);
|
||||
preOrder(root.right);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TreeNode root = TreeNode.listToTree(Arrays.asList(1, 7, 3, 4, 5, 6, 7));
|
||||
System.out.println("\nInitialize binary tree");
|
||||
PrintUtil.printTree(root);
|
||||
|
||||
// Pre-order traversal
|
||||
res = new ArrayList<>();
|
||||
preOrder(root);
|
||||
|
||||
System.out.println("\nOutput all nodes with value 7");
|
||||
List<Integer> vals = new ArrayList<>();
|
||||
for (TreeNode node : res) {
|
||||
vals.add(node.val);
|
||||
}
|
||||
System.out.println(vals);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* File: preorder_traversal_ii_compact.java
|
||||
* Created Time: 2023-04-16
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class preorder_traversal_ii_compact {
|
||||
static List<TreeNode> path;
|
||||
static List<List<TreeNode>> res;
|
||||
|
||||
/* Pre-order traversal: Example two */
|
||||
static void preOrder(TreeNode root) {
|
||||
if (root == null) {
|
||||
return;
|
||||
}
|
||||
// Attempt
|
||||
path.add(root);
|
||||
if (root.val == 7) {
|
||||
// Record solution
|
||||
res.add(new ArrayList<>(path));
|
||||
}
|
||||
preOrder(root.left);
|
||||
preOrder(root.right);
|
||||
// Retract
|
||||
path.remove(path.size() - 1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TreeNode root = TreeNode.listToTree(Arrays.asList(1, 7, 3, 4, 5, 6, 7));
|
||||
System.out.println("\nInitialize binary tree");
|
||||
PrintUtil.printTree(root);
|
||||
|
||||
// Pre-order traversal
|
||||
path = new ArrayList<>();
|
||||
res = new ArrayList<>();
|
||||
preOrder(root);
|
||||
|
||||
System.out.println("\nOutput all root-to-node 7 paths");
|
||||
for (List<TreeNode> path : res) {
|
||||
List<Integer> vals = new ArrayList<>();
|
||||
for (TreeNode node : path) {
|
||||
vals.add(node.val);
|
||||
}
|
||||
System.out.println(vals);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* File: preorder_traversal_iii_compact.java
|
||||
* Created Time: 2023-04-16
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class preorder_traversal_iii_compact {
|
||||
static List<TreeNode> path;
|
||||
static List<List<TreeNode>> res;
|
||||
|
||||
/* Pre-order traversal: Example three */
|
||||
static void preOrder(TreeNode root) {
|
||||
// Pruning
|
||||
if (root == null || root.val == 3) {
|
||||
return;
|
||||
}
|
||||
// Attempt
|
||||
path.add(root);
|
||||
if (root.val == 7) {
|
||||
// Record solution
|
||||
res.add(new ArrayList<>(path));
|
||||
}
|
||||
preOrder(root.left);
|
||||
preOrder(root.right);
|
||||
// Retract
|
||||
path.remove(path.size() - 1);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TreeNode root = TreeNode.listToTree(Arrays.asList(1, 7, 3, 4, 5, 6, 7));
|
||||
System.out.println("\nInitialize binary tree");
|
||||
PrintUtil.printTree(root);
|
||||
|
||||
// Pre-order traversal
|
||||
path = new ArrayList<>();
|
||||
res = new ArrayList<>();
|
||||
preOrder(root);
|
||||
|
||||
System.out.println("\nOutput all root-to-node 7 paths, not including nodes with value 3");
|
||||
for (List<TreeNode> path : res) {
|
||||
List<Integer> vals = new ArrayList<>();
|
||||
for (TreeNode node : path) {
|
||||
vals.add(node.val);
|
||||
}
|
||||
System.out.println(vals);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* File: preorder_traversal_iii_template.java
|
||||
* Created Time: 2023-04-16
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import utils.*;
|
||||
import java.util.*;
|
||||
|
||||
public class preorder_traversal_iii_template {
|
||||
/* Determine if the current state is a solution */
|
||||
static boolean isSolution(List<TreeNode> state) {
|
||||
return !state.isEmpty() && state.get(state.size() - 1).val == 7;
|
||||
}
|
||||
|
||||
/* Record solution */
|
||||
static void recordSolution(List<TreeNode> state, List<List<TreeNode>> res) {
|
||||
res.add(new ArrayList<>(state));
|
||||
}
|
||||
|
||||
/* Determine if the choice is legal under the current state */
|
||||
static boolean isValid(List<TreeNode> state, TreeNode choice) {
|
||||
return choice != null && choice.val != 3;
|
||||
}
|
||||
|
||||
/* Update state */
|
||||
static void makeChoice(List<TreeNode> state, TreeNode choice) {
|
||||
state.add(choice);
|
||||
}
|
||||
|
||||
/* Restore state */
|
||||
static void undoChoice(List<TreeNode> state, TreeNode choice) {
|
||||
state.remove(state.size() - 1);
|
||||
}
|
||||
|
||||
/* Backtracking algorithm: Example three */
|
||||
static void backtrack(List<TreeNode> state, List<TreeNode> choices, List<List<TreeNode>> res) {
|
||||
// Check if it's a solution
|
||||
if (isSolution(state)) {
|
||||
// Record solution
|
||||
recordSolution(state, res);
|
||||
}
|
||||
// Traverse all choices
|
||||
for (TreeNode choice : choices) {
|
||||
// Pruning: check if the choice is legal
|
||||
if (isValid(state, choice)) {
|
||||
// Attempt: make a choice, update the state
|
||||
makeChoice(state, choice);
|
||||
// Proceed to the next round of selection
|
||||
backtrack(state, Arrays.asList(choice.left, choice.right), res);
|
||||
// Retract: undo the choice, restore to the previous state
|
||||
undoChoice(state, choice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
TreeNode root = TreeNode.listToTree(Arrays.asList(1, 7, 3, 4, 5, 6, 7));
|
||||
System.out.println("\nInitialize binary tree");
|
||||
PrintUtil.printTree(root);
|
||||
|
||||
// Backtracking algorithm
|
||||
List<List<TreeNode>> res = new ArrayList<>();
|
||||
backtrack(new ArrayList<>(), Arrays.asList(root), res);
|
||||
|
||||
System.out.println("\nOutput all root-to-node 7 paths, requiring paths not to include nodes with value 3");
|
||||
for (List<TreeNode> path : res) {
|
||||
List<Integer> vals = new ArrayList<>();
|
||||
for (TreeNode node : path) {
|
||||
vals.add(node.val);
|
||||
}
|
||||
System.out.println(vals);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
en/codes/java/chapter_backtracking/subset_sum_i.java
Normal file
55
en/codes/java/chapter_backtracking/subset_sum_i.java
Normal file
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* File: subset_sum_i.java
|
||||
* Created Time: 2023-06-21
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class subset_sum_i {
|
||||
/* Backtracking algorithm: Subset Sum I */
|
||||
static void backtrack(List<Integer> state, int target, int[] choices, int start, List<List<Integer>> res) {
|
||||
// When the subset sum equals target, record the solution
|
||||
if (target == 0) {
|
||||
res.add(new ArrayList<>(state));
|
||||
return;
|
||||
}
|
||||
// Traverse all choices
|
||||
// Pruning two: start traversing from start to avoid generating duplicate subsets
|
||||
for (int i = start; i < choices.length; i++) {
|
||||
// Pruning one: if the subset sum exceeds target, end the loop immediately
|
||||
// This is because the array is sorted, and later elements are larger, so the subset sum will definitely exceed target
|
||||
if (target - choices[i] < 0) {
|
||||
break;
|
||||
}
|
||||
// Attempt: make a choice, update target, start
|
||||
state.add(choices[i]);
|
||||
// Proceed to the next round of selection
|
||||
backtrack(state, target - choices[i], choices, i, res);
|
||||
// Retract: undo the choice, restore to the previous state
|
||||
state.remove(state.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Solve Subset Sum I */
|
||||
static List<List<Integer>> subsetSumI(int[] nums, int target) {
|
||||
List<Integer> state = new ArrayList<>(); // State (subset)
|
||||
Arrays.sort(nums); // Sort nums
|
||||
int start = 0; // Start point for traversal
|
||||
List<List<Integer>> res = new ArrayList<>(); // Result list (subset list)
|
||||
backtrack(state, target, nums, start, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] nums = { 3, 4, 5 };
|
||||
int target = 9;
|
||||
|
||||
List<List<Integer>> res = subsetSumI(nums, target);
|
||||
|
||||
System.out.println("Input array nums = " + Arrays.toString(nums) + ", target = " + target);
|
||||
System.out.println("All subsets summing to " + target + " res = " + res);
|
||||
}
|
||||
}
|
||||
53
en/codes/java/chapter_backtracking/subset_sum_i_naive.java
Normal file
53
en/codes/java/chapter_backtracking/subset_sum_i_naive.java
Normal file
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* File: subset_sum_i_naive.java
|
||||
* Created Time: 2023-06-21
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class subset_sum_i_naive {
|
||||
/* Backtracking algorithm: Subset Sum I */
|
||||
static void backtrack(List<Integer> state, int target, int total, int[] choices, List<List<Integer>> res) {
|
||||
// When the subset sum equals target, record the solution
|
||||
if (total == target) {
|
||||
res.add(new ArrayList<>(state));
|
||||
return;
|
||||
}
|
||||
// Traverse all choices
|
||||
for (int i = 0; i < choices.length; i++) {
|
||||
// Pruning: if the subset sum exceeds target, skip that choice
|
||||
if (total + choices[i] > target) {
|
||||
continue;
|
||||
}
|
||||
// Attempt: make a choice, update elements and total
|
||||
state.add(choices[i]);
|
||||
// Proceed to the next round of selection
|
||||
backtrack(state, target, total + choices[i], choices, res);
|
||||
// Retract: undo the choice, restore to the previous state
|
||||
state.remove(state.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Solve Subset Sum I (including duplicate subsets) */
|
||||
static List<List<Integer>> subsetSumINaive(int[] nums, int target) {
|
||||
List<Integer> state = new ArrayList<>(); // State (subset)
|
||||
int total = 0; // Subset sum
|
||||
List<List<Integer>> res = new ArrayList<>(); // Result list (subset list)
|
||||
backtrack(state, target, total, nums, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] nums = { 3, 4, 5 };
|
||||
int target = 9;
|
||||
|
||||
List<List<Integer>> res = subsetSumINaive(nums, target);
|
||||
|
||||
System.out.println("Input array nums = " + Arrays.toString(nums) + ", target = " + target);
|
||||
System.out.println("All subsets summing to " + target + " res = " + res);
|
||||
System.out.println("Please note that the result of this method includes duplicate sets");
|
||||
}
|
||||
}
|
||||
60
en/codes/java/chapter_backtracking/subset_sum_ii.java
Normal file
60
en/codes/java/chapter_backtracking/subset_sum_ii.java
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* File: subset_sum_ii.java
|
||||
* Created Time: 2023-06-21
|
||||
* Author: krahets (krahets@163.com)
|
||||
*/
|
||||
|
||||
package chapter_backtracking;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class subset_sum_ii {
|
||||
/* Backtracking algorithm: Subset Sum II */
|
||||
static void backtrack(List<Integer> state, int target, int[] choices, int start, List<List<Integer>> res) {
|
||||
// When the subset sum equals target, record the solution
|
||||
if (target == 0) {
|
||||
res.add(new ArrayList<>(state));
|
||||
return;
|
||||
}
|
||||
// Traverse all choices
|
||||
// Pruning two: start traversing from start to avoid generating duplicate subsets
|
||||
// Pruning three: start traversing from start to avoid repeatedly selecting the same element
|
||||
for (int i = start; i < choices.length; i++) {
|
||||
// Pruning one: if the subset sum exceeds target, end the loop immediately
|
||||
// This is because the array is sorted, and later elements are larger, so the subset sum will definitely exceed target
|
||||
if (target - choices[i] < 0) {
|
||||
break;
|
||||
}
|
||||
// Pruning four: if the element equals the left element, it indicates that the search branch is repeated, skip it
|
||||
if (i > start && choices[i] == choices[i - 1]) {
|
||||
continue;
|
||||
}
|
||||
// Attempt: make a choice, update target, start
|
||||
state.add(choices[i]);
|
||||
// Proceed to the next round of selection
|
||||
backtrack(state, target - choices[i], choices, i + 1, res);
|
||||
// Retract: undo the choice, restore to the previous state
|
||||
state.remove(state.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Solve Subset Sum II */
|
||||
static List<List<Integer>> subsetSumII(int[] nums, int target) {
|
||||
List<Integer> state = new ArrayList<>(); // State (subset)
|
||||
Arrays.sort(nums); // Sort nums
|
||||
int start = 0; // Start point for traversal
|
||||
List<List<Integer>> res = new ArrayList<>(); // Result list (subset list)
|
||||
backtrack(state, target, nums, start, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
int[] nums = { 4, 4, 5 };
|
||||
int target = 9;
|
||||
|
||||
List<List<Integer>> res = subsetSumII(nums, target);
|
||||
|
||||
System.out.println("Input array nums = " + Arrays.toString(nums) + ", target = " + target);
|
||||
System.out.println("All subsets summing to " + target + " res = " + res);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user