File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -27,22 +27,22 @@ namespace Subsets {
27
27
* @returns count of the number of subsets with required sum
28
28
*/
29
29
30
- std::uint64_t subset_sum (int sum, std::vector<int > &in_arr) {
30
+ std::uint64_t subset_sum (int sum, const std::vector<int > &in_arr) {
31
31
int nelement = in_arr.size (); // number of subset element
32
32
int count_of_subset = 0 ;
33
33
34
- for (int i=0 ; i < (1 << (nelement)); i++) {
34
+ for (int i=0 ; i < (1 << (nelement)); i++) {
35
35
std::vector<int > subset;
36
- for ( int j=0 ; j < nelement ; j++) {
36
+ for ( int j=0 ; j < nelement ; j++) {
37
37
if (i & (1 <<j)) {
38
38
subset.push_back (in_arr[j]);
39
39
}
40
40
}
41
41
int check=0 ;
42
- for ( int k=0 ; k < subset.size (); k++) {
42
+ for ( int k=0 ; k < subset.size (); k++) {
43
43
check += subset[k];
44
44
}
45
- if (check==sum) {
45
+ if (check==sum) {
46
46
count_of_subset++;
47
47
}
48
48
}
You can’t perform that action at this time.
0 commit comments