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 lengthOfLongestSubstring(string s) { | |
// IMPORTANT: Please reset any member data you declared, as | |
// the same Solution instance will be reused for each test case. | |
int bitmap[256]; | |
std::memset(bitmap,0,sizeof(bitmap)); | |
int maxLen = 0; | |
int curLen = 0; | |
for(int i = 0; i<(int)s.length();) |
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 maxArea(vector<int> &height) { | |
// IMPORTANT: Please reset any member data you declared, as | |
// the same Solution instance will be reused for each test case. | |
size_t i = 0, j = height.size()-1; | |
size_t maxSize = 0; | |
while(i<j) | |
{ | |
size_t curSize = 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: | |
string intToRoman(int num) { | |
// IMPORTANT: Please reset any member data you declared, as | |
// the same Solution instance will be reused for each test case. | |
/*Symbol Value | |
I 1 | |
V 5 | |
X 10 | |
L 50 |
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: | |
string longestCommonPrefix(vector<string> &strs) { | |
// IMPORTANT: Please reset any member data you declared, as | |
// the same Solution instance will be reused for each test case. | |
if(strs.size() == 0) | |
return string(); | |
if(strs.size() == 1) | |
return strs[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 singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
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: | |
void twoSum(int first, int last, const vector<int> sVec, int target, vector<vector<int> > & res) | |
{ | |
int prei = INT_MAX; | |
int prej = INT_MAX; | |
while(first < last) | |
{ | |
int i = sVec[first]; |
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: | |
bool isValid(string s) { | |
// IMPORTANT: Please reset any member data you declared, as | |
// the same Solution instance will be reused for each test case. | |
static unordered_map<char,char> bMap({ {'(',0}, {')',0}, {'[',1}, {']',1}, {'{',2}, {'}',2} }); | |
stack<char> ss; | |
for(int i = 0; i<s.length(); ++i) | |
{ | |
char c = 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
/** | |
* Definition for singly-linked list. | |
* struct ListNode { | |
* int val; | |
* ListNode *next; | |
* ListNode(int x) : val(x), next(NULL) {} | |
* }; | |
*/ | |
class Solution { | |
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: | |
void _lComb(int idx, int idxStr, const string & digits, string & str, vector<string> & res) | |
{ | |
static string dMap[10] = {" ","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"}; | |
if(idx == digits.length()) | |
{ | |
res.push_back(str); | |
}else |
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: | |
void _genParen(int numL, int numR, string & sol, vector<string> & res) | |
{ | |
if(numL == 0 && numR == 0) | |
res.push_back(sol); | |
else | |
{ | |
// numR should be > numL | |
if(numL == numR) |
OlderNewer