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
C++: | |
class Solution { | |
public: | |
bool isMatch(const char *s, const char *p) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(*p=='\0') return *s=='\0'; | |
if(*(p+1)!='*') | |
return ((*s==*p)||(*s!='\0'&&*p=='.'))&&isMatch(s+1,p+1); | |
while((*s==*p)||(*s!='\0'&&*p=='.')){ |
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
C++: | |
class Solution { | |
public: | |
int maxArea(vector<int> &height) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int low=0; | |
int high=height.size()-1; | |
int ret=0; | |
while(low<high){ |
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
C++: | |
class Solution { | |
public: | |
string intToRoman(int num) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
const static char *Roman="IVXLCDM"; | |
string ret; | |
for(int base=0;num;num /=10,base=base+2){ | |
int cur=num%10; |
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
C++: | |
class Solution { | |
public: | |
int romanToInt(string s) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int ret=0; | |
for(int i=0;i<s.size();i++){ | |
if(i<s.size()-1){ | |
if(getVal(s[i])<getVal(s[i+1])) ret -=getVal(s[i]); |
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
(1)C++: | |
#include<cstdio> | |
using namespace std; | |
bool find(int matrix[1000][1000],int rows,int columns,int number){ | |
if(matrix!=NULL&&rows>0&&columns>0){ | |
int rowIndex=0; | |
int colIndex=columns-1; | |
while(rowIndex<rows&&colIndex>=0){ | |
if(matrix[rowIndex][colIndex]==number) return true; |
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
C++: | |
class Solution { | |
private: | |
vector<vector<int>> ret; | |
public: | |
vector<vector<int> > fourSum(vector<int> &num, int target) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
ret.clear(); | |
if(num.size()<4) return ret; |
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
C++: | |
class Solution { | |
public: | |
int threeSumClosest(vector<int> &num, int target) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
int ret; | |
int temp=INT_MAX; | |
sort(num.begin(),num.end()); | |
for(int i=0;i<num.size()-2;i++){ |
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
C++: | |
class Solution { | |
private: | |
vector<vector<int>> ret; | |
public: | |
vector<vector<int> > threeSum(vector<int> &num) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
ret.clear(); | |
if(num.size()<3) return ret; |
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
(1)O(n*m) | |
C++: | |
class Solution { | |
public: | |
vector<int> twoSum(vector<int> &numbers, int target) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
vector<int> ret(2); | |
for(int i=0;i<numbers.size();i++){ | |
int temp=target-numbers[i]; |
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
C++: | |
class Solution { | |
public: | |
string longestCommonPrefix(vector<string> &strs) { | |
// Start typing your C/C++ solution below | |
// DO NOT write int main() function | |
if(strs.size()==0) return ""; | |
if(strs.size()==1) return strs[0]; | |
string ret=""; | |
int maxLen=INT_MAX; |