Skip to content

Commit 4827805

Browse files
authored
Update subset_sum.cpp
1 parent 6334148 commit 4827805

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

backtracking/subset_sum.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ namespace Subsets {
2727
* @returns count of the number of subsets with required sum
2828
*/
2929

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) {
3131
int nelement = in_arr.size(); //number of subset element
3232
int count_of_subset = 0;
3333

34-
for(int i=0; i < (1 << (nelement)); i++) {
34+
for (int i=0; i < (1 << (nelement)); i++) {
3535
std::vector<int> subset;
36-
for( int j=0 ; j < nelement ; j++) {
36+
for ( int j=0 ; j < nelement ; j++) {
3737
if (i & (1<<j)) {
3838
subset.push_back(in_arr[j]);
3939
}
4040
}
4141
int check=0;
42-
for( int k=0 ; k < subset.size(); k++) {
42+
for ( int k=0 ; k < subset.size(); k++) {
4343
check += subset[k];
4444
}
45-
if(check==sum) {
45+
if (check==sum) {
4646
count_of_subset++;
4747
}
4848
}

0 commit comments

Comments
 (0)