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 { | |
#define ll long long | |
public: | |
long long largestSquareArea(vector<vector<int>>& bottomLeft, vector<vector<int>>& topRight) { | |
int n = bottomLeft.size(); | |
vector<vector<int>> rectangles(n,vector<int>(4)); | |
for(int i=0;i<n;i++){ | |
rectangles[i][0] = bottomLeft[i][0]; | |
rectangles[i][1] = bottomLeft[i][1]; | |
rectangles[i][2] = topRight[i][0]; |
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 { | |
public: | |
int maxNumberOfFamilies(int n, vector<vector<int>>& rseats) { | |
rseats.push_back({0,10}); | |
rseats.push_back({n+1,1}); | |
sort(rseats.begin(),rseats.end()); | |
int size = rseats.size(); | |
int count = 0; | |
int skipRows,skipCols; |
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 { | |
#define SIZE 256+2 | |
bool equalFreq(vector<int>& curr,vector<int>& freq){//Check frequency of current window with freq(t) | |
for(int i=0;i<SIZE;++i) | |
if(freq[i]>0 and curr[i]<freq[i]) | |
return false; | |
return true; | |
} | |
public: | |
string minWindow(string s, string t) { |
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 { | |
int count(vector<vector<int>>& matrix,int val){ | |
int c=0,n=matrix.size(),lb; | |
for(int i=0;i<n;++i){ | |
lb = upper_bound(matrix[i].begin(),matrix[i].end(),val)-matrix[i].begin(); | |
c += lb; | |
} | |
return c; | |
} | |
public: |
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 { | |
public: | |
int hammingDistance(int x, int y) { | |
int xorVal = x^y; | |
int countSetBits = 0; | |
while(xorVal){ | |
if(xorVal & 1) | |
countSetBits++; | |
xorVal >>= 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
class Solution { | |
double solve(vector<int>& nums1,int n,vector<int>& nums2,int m){ | |
if(n>m) return solve(nums2,m,nums1,n);//To make time=O(min(logN,logM)) | |
int low=0,high=n; | |
while(low<=high){ | |
int partitionX=(low+high)/2; | |
int partitionY=(m+n+1)/2-partitionX; | |
int maxLeftX = partitionX==0?INT_MIN:nums1[partitionX-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
class Solution { | |
#define N 2 | |
struct trienode { | |
int number; | |
trienode* child[N]; | |
trienode(){ | |
for(int i=0;i<N;++i) | |
child[i]=NULL; | |
} | |
}; |
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 { | |
int solve(vector<int>& sum1,vector<int>& sum2,int tot){ | |
int m = sum1.size(),n = sum2.size(); | |
int minDiff = INT_MAX; | |
for(int i=0;i<m;++i){ | |
int target = tot/2-sum1[i]; | |
int lb = lower_bound(sum2.begin(),sum2.end(),target)-sum2.begin(); | |
if(lb==sum2.size()) | |
minDiff = min(minDiff,abs(tot-2*(sum1[i]+sum2[lb-1]))); | |
else if(lb==0) |
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
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode() : val(0), left(nullptr), right(nullptr) {} | |
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} | |
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} | |
* }; |
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
/** | |
* Definition for a binary tree node. | |
* struct TreeNode { | |
* int val; | |
* TreeNode *left; | |
* TreeNode *right; | |
* TreeNode() : val(0), left(nullptr), right(nullptr) {} | |
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} | |
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {} | |
* }; |