摘要: ``` class Solution { public: int maxArea(vector& height) { int res = 0, i = 0, j = height.size() 1; while (i 阅读全文
posted @ 2019-04-08 17:24 JohnRed 阅读(62) 评论(0) 推荐(0) 编辑
摘要: ``` 定义一个二维的DP数组,其中dp[i][j]表示s[0,i)和p[0,j)是否match,然后有下面三种情况 1. P[i][j] = P[i - 1][j - 1], if p[j - 1] != '*' && (s[i - 1] == p[j - 1] || p[j - 1] == '.'); 2. P[i][j] = P[i][j - 2], if p[j - 1] == '*'... 阅读全文
posted @ 2019-04-08 17:22 JohnRed 阅读(76) 评论(0) 推荐(0) 编辑
摘要: ``` class Solution { public: bool isPalindrome(int x) { if (x = 10) div *= 10; while (x > 0) { int left = x / div; int right = x % 10; if (left ... 阅读全文
posted @ 2019-04-08 17:19 JohnRed 阅读(74) 评论(0) 推荐(0) 编辑
摘要: ``` class Solution { public: int myAtoi(string str) { if (str.empty()) return 0; int sign = 1, base = 0, i = 0, n = str.size(); while (i = '0' && str[i] INT_MAX / 10 || (b... 阅读全文
posted @ 2019-04-08 17:12 JohnRed 阅读(76) 评论(0) 推荐(0) 编辑
摘要: ``` class Solution { public: int reverseInteger(int n) { long long res = 0; while (n != 0) { res = 10 * res + n % 10; n /= 10; } return (res... 阅读全文
posted @ 2019-04-08 17:07 JohnRed 阅读(58) 评论(0) 推荐(0) 编辑
摘要: ``` class Solution { public: string convert(string s, int nRows) { if (nRows 阅读全文
posted @ 2019-04-08 17:05 JohnRed 阅读(75) 评论(0) 推荐(0) 编辑
摘要: ``` class Solution { public: string longestPalindrome(string s) { if (s.empty()) return ""; int dp[s.size()][s.size()] = {0}, left = 0, right = 0, len 阅读全文
posted @ 2019-04-08 17:02 JohnRed 阅读(107) 评论(0) 推荐(0) 编辑
摘要: ``` class Solution { public: double findMedianSortedArrays(vector& nums1, vector& nums2) { int m = nums1.size(), n = nums2.size(); if (m R2) left = mid2 + 1; else if (... 阅读全文
posted @ 2019-04-08 16:34 JohnRed 阅读(69) 评论(0) 推荐(0) 编辑
摘要: ``` class Solution { public: int lengthOfLongestSubstring(string s) { int res = 0, left = -1, n = s.size(); unordered_map m; for (int i = 0; i left) { left... 阅读全文
posted @ 2019-04-08 16:32 JohnRed 阅读(76) 评论(0) 推荐(0) 编辑
摘要: ``` class Solution { public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode *dummy = new ListNode(-1), *cur = dummy; int carry = 0; while (l1 || l2) { ... 阅读全文
posted @ 2019-04-08 16:21 JohnRed 阅读(82) 评论(0) 推荐(0) 编辑