This file contains hidden or 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) { | |
| // Start typing your C/C++ solution below | |
| // DO NOT write int main() function | |
| int size = height.size(); | |
| int left = 0; | |
This file contains hidden or 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) { | |
| string roman[13] = {"M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"}; | |
| int cost[13] = {1000,900,500,400,100,90,50,40,10,9,5,4,1}; | |
| string result; | |
| while(num > 0) { | |
| for(int i = 0; i < 13; i++) { | |
| int times = num/cost[i]; |
This file contains hidden or 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 romanToInt(string s) { | |
| int len = s.length(); | |
| int result = 0; | |
| map<char, int> myMap; | |
| myMap['I'] = 1; | |
| myMap['V'] = 5; |
This file contains hidden or 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) { | |
| string prefix; | |
| int size = strs.size(); | |
| if(size <= 0) return prefix ; | |
This file contains hidden or 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: | |
| vector<vector<int> > threeSum(vector<int> &num) { | |
| sort(num.begin(), num.end()); | |
| int size = num.size(); | |
| vector<vector<int> > results; |
This file contains hidden or 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 threeSumClosest(vector<int> &num, int target) { | |
| int gap = INT_MAX; | |
| sort(num.begin(), num.end()); | |
| int size = num.size(); | |
This file contains hidden or 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: | |
| char letter[10][4] ={{' ',' ',' ',' '}, | |
| {' ',' ',' ',' '}, | |
| {'a','b','c',' '}, | |
| {'d','e','f',' '}, | |
| {'g','h','i',' '}, | |
| {'j','k','l',' '}, | |
| {'m','n','o',' '}, | |
| {'p','q','r','s'}, |
This file contains hidden or 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: | |
| vector<vector<int> > fourSum(vector<int> &num, int target) { | |
| // Note: The Solution object is instantiated only once and is reused by each test case. | |
| vector<int> tmp; | |
| vector<vector<int>> results; | |
| if(num.empty()) return results; | |
| sort(num.begin(), num.end()); | |
| for(int i=0; i<num.size(); i++) | |
| { |
This file contains hidden or 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: | |
| ListNode *removeNthFromEnd(ListNode *head, int n) { | |
| if(head == NULL) return head; | |
| ListNode * dummy = new ListNode(-1); | |
| dummy->next = head; | |
This file contains hidden or 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) { | |
| int len = s.length(); | |
| if(len <= 1) return false; | |
| stack<char> myStack; | |