Skip to content

Commit caae937

Browse files
committed
Added More Solutions
1 parent 67de795 commit caae937

File tree

6 files changed

+62
-0
lines changed

6 files changed

+62
-0
lines changed

Combination of K numbers out of range [1,n]/Readme.md

Whitespace-only changes.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class Solution {
2+
public:
3+
vector<vector<int>> combine(int n, int k){
4+
vector<vector<int>> output;
5+
vector <int> combination;
6+
combine(output, combination, n, k, 1);
7+
return output;
8+
}
9+
10+
private:
11+
12+
void combine(vector<vector<int>> & output, vector<int> combination, int n, int k, int i){
13+
if (combination.size() == k){
14+
output.push_back(combination);
15+
return;
16+
}
17+
18+
for (int j=i; j<=n; j++){
19+
combination.push_back(j);
20+
combine(output, combination, n, k, j+1);
21+
combination.pop_back();
22+
}
23+
}
24+
};

Consecutive Number Sum/Readme.md

Whitespace-only changes.

Consecutive Number Sum/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
def consecutiveNumbersSum(self, n: int) -> int:
3+
4+
if n == 1:
5+
return 1
6+
7+
res = 1
8+
9+
for i in range(2, int(n**0.5 + 1)):
10+
if n % i == 0:
11+
if i % 2 == 1:
12+
res += 1
13+
14+
j = (n // i)
15+
16+
if i != j and j % 2 == 1:
17+
res += 1
18+
19+
if n % 2 == 1:
20+
res +=1
21+
22+
return res

Find Duplicates/Readme.md

Whitespace-only changes.

Find Duplicates/main.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
class Solution {
2+
public List <Integer> findDuplicates(int[] nums){
3+
List <Integer> result = new ArrayList<>();
4+
5+
for (int i=0; i<nums.length; i++){
6+
int index = Math.abs(nums[i] - 1);
7+
8+
if (nums[index] < 0)
9+
{
10+
result.add(index+1);
11+
}
12+
nums[index] = nums[index] * -1;
13+
}
14+
return result;
15+
}
16+
}

0 commit comments

Comments
 (0)