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
| #include <algorithm> | |
| using namespace std; | |
| class Solution { | |
| public: | |
| int maxArea(vector<int> &height) { | |
| int ret = 0; | |
| int left = 0, right = height.size() - 1; | |
| while (left < right) { | |
| ret = max(ret, (right - left) * min(height[left], height[right])); |
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
| /** | |
| * Definition for binary tree | |
| * struct TreeNode { | |
| * int val; | |
| * TreeNode *left; | |
| * TreeNode *right; | |
| * TreeNode(int x) : val(x), left(NULL), right(NULL) {} | |
| * }; | |
| */ | |
| class Solution { |
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
| /** | |
| * Definition for singly-linked list. | |
| * struct ListNode { | |
| * int val; | |
| * ListNode *next; | |
| * ListNode(int x) : val(x), next(NULL) {} | |
| * }; | |
| */ | |
| /** | |
| * Definition for binary tree |
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
| #!/usr/bin/python | |
| def get_less_cnt(buf, pivot): | |
| left, right = 0, len(buf) - 1 | |
| ret = 0 | |
| while left <= right: | |
| mid = (left + right) / 2 | |
| if buf[mid] <= pivot: | |
| ret = max(ret, mid) | |
| left = mid + 1 |
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 countAndSay(int n) { | |
| string ret = "1"; | |
| while (--n) { | |
| stringstream ss; | |
| int cnt = 0; | |
| for (int i = 0; i < ret.length(); ++i) { | |
| cnt++; | |
| if (i == ret.length() - 1 || ret[i] != ret[i + 1]) { |
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 numDecodings(string s) { | |
| if (s.empty()) | |
| return 0; | |
| int n = s.length(); | |
| int f[3] = {1, 1, 1}; | |
| for (int i = 0; i < n; ++i) { | |
| f[i % 3] = 0; | |
| if (s[i] > '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: | |
| int numDistinct(string S, string T) { | |
| int n = S.length(); | |
| int m = T.length(); | |
| if (n == 0 || m == 0) | |
| return 0; | |
| int **f = new int*[n]; | |
| for (int i = 0; i < n; ++i) | |
| f[i] = new int[m]; |
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 divide(int dividend_, int divisor_) { | |
| long long dividend = dividend_, divisor = divisor_; | |
| int flag = 1; | |
| if (dividend < 0) { | |
| flag *= -1; | |
| dividend = -dividend; | |
| } | |
| if (divisor < 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: | |
| int minDistance(string word1, string word2) { | |
| int n = word1.size(); | |
| int m = word2.size(); | |
| if (n == 0 || m == 0) | |
| return max(n, m); | |
| int **f = new int*[n]; | |
| for (int i = 0; i < n; ++i) | |
| f[i] = new int[m]; |
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 firstMissingPositive(int A[], int n) { | |
| for (int i = 0; i < n; ++i) | |
| while (A[i] >= 1 && A[i] <= n && A[i] != i + 1 && A[i] != A[A[i] - 1]) | |
| swap(A[i], A[A[i] - 1]); | |
| int ret; | |
| for (ret = 1; ret <= n; ++ret) | |
| if (A[ret - 1] != ret) | |
| break; |