This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define m 1000000007 | |
int Solution::cntBits(vector<int> &A) { | |
long long count=0; | |
int t = 1; | |
for(int i = 1; i < 32 ; i++){ | |
long long one = 0, zero = 0; | |
if( i==1 ){ | |
t = 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int max(int a, int b ){ | |
if( a > b ) | |
return a; | |
return b; | |
} | |
int min(int a, int b ){ | |
if( a < b ) | |
return a; | |
return b; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Web Club Codebuddy Week 2 | |
int BinarySearch(const vector<int> &A,int B,int l,int h) { | |
int m = (l+h)/2; | |
if(l>h) | |
return -1; | |
if(A[m] == B) | |
return m; | |
if(A[m] < B) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Solution: | |
# @param A : integer | |
# @return a list of strings | |
def generateParenthesis(self, A): | |
l=[] | |
if(A>=1): | |
l=['('] | |
while True: | |
no=nc=0 | |
nl=[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int Solution::threeSumClosest(vector<int> &A, int B) { | |
sort(A.begin(), A.end()); | |
int sum = A[0] + A[1] + A[2]; | |
for(int i = 0; i < A.size()-2; i++) | |
{ | |
int j = i+1, k = A.size()-1; | |
while(j < k) | |
{ | |
int s = A[i]+A[j]+A[k]; | |
if(abs(B-s) < abs(B-sum)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define M 1000003 | |
unsigned int factorial(unsigned int n) | |
{ | |
if (n == 0) | |
return 1; | |
return ((n%M) * (factorial(n - 1)%M))%M; | |
} | |
int Solution::findRank(string A) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vector<int> Solution::subUnsort(vector<int> &A) { | |
vector<int> r; | |
vector<int> t; | |
int f=0,l=A.size()-1; | |
int i,s=A.size(); | |
for(i=0;i<s-1;i++){ | |
if(A[i]>A[i+1]){ | |
f=i; | |
break; | |
} |
NewerOlder