Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions AllFactors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<bits/stdc++.h>

vector<int> Solution::allFactors(int num){

vector<int> ans;
for(int i = 1; i <= (int)(sqrt(num)); i++){
if(num%i == 0){
if(num/i == i){
ans.push_back(i);
}
else{
ans.push_back(i);
ans.push_back(num / i);
}
}
}
sort(ans.begin(), ans.end());
return ans;

}
19 changes: 19 additions & 0 deletions BinaryRepresentation.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<bits/stdc++.h>

string Solution::findDigitsInBinary(int num){

string ans = "";
if(num == 0)
return "0";
while(num != 1){
if(num%2 == 0)
ans += "0";
else
ans += "1";
num /= 2;
}
ans += "1";
reverse(ans.begin(), ans.end());
return ans;

}
14 changes: 14 additions & 0 deletions ExcelColumnNumber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<bits/stdc++.h>

int Solution::titleToNumber(string s){

int n = s.size();
int ans = 0;
int cnt = 0;
for(int i = n - 1; i >= 0; i--){
ans += (pow(26, cnt) * (s[i] - 'A' + 1));
cnt++;
}
return ans;

}
26 changes: 26 additions & 0 deletions ExcelColumnTitle.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<bits/stdc++.h>

string Solution::convertToTitle(int num){

unordered_map<int, char> mp = {{1, 'A'}, {2, 'B'}, {3, 'C'}, {4, 'D'}, {5, 'E'},
{6, 'F'}, {7, 'G'}, {8, 'H'}, {9, 'I'}, {10, 'J'},
{11, 'K'}, {12, 'L'}, {13, 'M'}, {14, 'N'}, {15, 'O'},
{16, 'P'}, {17, 'Q'}, {18, 'R'}, {19, 'S'}, {20, 'T'},
{21, 'U'}, {22, 'V'}, {23, 'W'}, {24, 'X'}, {25, 'Y'}, {26, 'Z'}};
string ans = "";
while(num != 0){
int rem = num % 26;
if(rem == 0){
rem = 26;
num /= 26;
num -= 1;
}
else{
num /= 26;
}
ans += mp[rem];
}
reverse(ans.begin(), ans.end());
return ans;

}