摘要:
class Solution { public: int searchInsert(vector& nums, int target) { if (nums.back() 阅读全文
posted @ 2019-04-08 21:07
JohnRed
阅读(74)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector searchRange(vector& nums, int target) { vector res(2, 1); int left = 0, right = nums.size() 1; while (left 阅读全文
posted @ 2019-04-08 21:05
JohnRed
阅读(110)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int search(vector& nums, int target) { int left = 0, right = nums.size() - 1; while (left = target) left = mid + 1; else right = mid - ... 阅读全文
posted @ 2019-04-08 20:58
JohnRed
阅读(73)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int longestValidParentheses(string s) { int result=0; s=')'+s; vector dp(s.length(),0); for(int i=1;i 阅读全文
posted @ 2019-04-08 20:56
JohnRed
阅读(100)
评论(0)
推荐(0)
摘要:
class Solution { public: void nextPermutation(vector& nums) {int n = nums.size(), i = n 2, j = n 1; while (i = 0 && nums[i] = nums[i + 1]) i; if (i = 阅读全文
posted @ 2019-04-08 20:52
JohnRed
阅读(75)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector findSubstring(string s, vector& words) { vector res; if (s.empty() || words.empty()) return res; int n = words.size(), m = words[0].size... 阅读全文
posted @ 2019-04-08 20:50
JohnRed
阅读(80)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int divide(int dividend, int divisor) { if (divisor == 0 || (dividend == INT_MIN && divisor == 1)) return INT_MAX; long l 阅读全文
posted @ 2019-04-08 19:57
JohnRed
阅读(64)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int removeElement(vector& nums, int val) { int res = 0; for (int i = 0; i 阅读全文
posted @ 2019-04-08 19:53
JohnRed
阅读(70)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int removeDuplicates(vector& nums) { if (nums.empty()) return 0; int pre = 0, cur = 0, n = nums.size(); while (cur 阅读全文
posted @ 2019-04-08 19:52
JohnRed
阅读(68)
评论(0)
推荐(0)
摘要:
``` class Solution { public: ListNode* reverseKGroup(ListNode* head, int k) { if (!head || k == 1) return head; ListNode *dummy = new ListNode(-1), *pre = dummy, *cur = head; ... 阅读全文
posted @ 2019-04-08 19:51
JohnRed
阅读(76)
评论(0)
推荐(0)
摘要:
```
class Solution {
public: ListNode* swapPairs(ListNode* head) { ListNode *dummy = new ListNode(-1), *pre = dummy; dummy->next = head; while (pre->next && pre->next->next... 阅读全文
posted @ 2019-04-08 19:48
JohnRed
阅读(88)
评论(0)
推荐(0)
摘要:
``` class Solution { public: ListNode* mergeKLists(vector& lists) { if (lists.empty()) return NULL; int n = lists.size(); while (n > 1) { int k = (n + 1) / 2; ... 阅读全文
posted @ 2019-04-08 19:43
JohnRed
阅读(67)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector generateParenthesis(int n) { vector res; generateParenthesisDFS(n, n, "", res); return res; } void generateParenthesisDFS(int le... 阅读全文
posted @ 2019-04-08 19:38
JohnRed
阅读(78)
评论(0)
推荐(0)
摘要:
``` class Solution { public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode *dummy = new ListNode(-1), *cur = dummy; while (l1 && l2) { if (l1->val val)... 阅读全文
posted @ 2019-04-08 19:37
JohnRed
阅读(67)
评论(0)
推荐(0)
摘要:
``` class Solution { public: bool isValid(string s) { stack parentheses; for (int i = 0; i 阅读全文
posted @ 2019-04-08 19:35
JohnRed
阅读(85)
评论(0)
推荐(0)
摘要:
``` class Solution { public: ListNode* removeNthFromEnd(ListNode* head, int n) { if (!head->next) return NULL; ListNode *pre = head, *cur = head; for (int i = 0; i next; ... 阅读全文
posted @ 2019-04-08 19:34
JohnRed
阅读(92)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector> fourSum(vector &nums, int target) { set> res; sort(nums.begin(), nums.end()); for (int i = 0; i i + 1 && nums[j] == nums[j - 1]) conti... 阅读全文
posted @ 2019-04-08 19:33
JohnRed
阅读(120)
评论(0)
推荐(0)
摘要:
``` class Solution { public: int threeSumClosest(vector& nums, int target) { int closest = nums[0] + nums[1] + nums[2]; int diff = abs(closest target) 阅读全文
posted @ 2019-04-08 19:32
JohnRed
阅读(86)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector> threeSum(vector& nums) { set> res; sort(nums.begin(), nums.end()); if (nums.empty() || nums.back() 0) return {}; for (int k = ... 阅读全文
posted @ 2019-04-08 18:20
JohnRed
阅读(74)
评论(0)
推荐(0)
摘要:
``` class Solution { public: string longestCommonPrefix(vector& strs) { if (strs.empty()) return ""; string res = ""; for (int j = 0; j = strs[i].size() || strs[i][j] != c)... 阅读全文
posted @ 2019-04-08 18:17
JohnRed
阅读(64)
评论(0)
推荐(0)
摘要:
``` 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
阅读(72)
评论(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
阅读(83)
评论(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
阅读(84)
评论(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
阅读(85)
评论(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
阅读(63)
评论(0)
推荐(0)
摘要:
``` class Solution { public: string convert(string s, int nRows) { if (nRows 阅读全文
posted @ 2019-04-08 17:05
JohnRed
阅读(81)
评论(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
阅读(115)
评论(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
阅读(80)
评论(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
阅读(83)
评论(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
阅读(90)
评论(0)
推荐(0)
摘要:
``` class Solution { public: vector twoSum(vector& nums, int target) { unordered_map m; for (int i = 0; i 阅读全文
posted @ 2019-04-08 16:18
JohnRed
阅读(115)
评论(0)
推荐(0)

浙公网安备 33010602011771号