随笔分类 -  Leetcode

摘要:class Solution { public: string mostCommonWord(string paragraph, vector& banned) { unordered_set s(banned.begin(), banned.end()); unordered_map m; int idx = 0; ... 阅读全文
posted @ 2018-11-20 00:15 JTechRoad 阅读(107) 评论(0) 推荐(0)
摘要:class Solution { public: vector removeComments(vector& source) { vector res; string ln; int state = 0; for (const auto & line : source) { for (int i = ... 阅读全文
posted @ 2018-11-20 00:02 JTechRoad 阅读(161) 评论(0) 推荐(0)
摘要:// see more at https://www.youtube.com/watch?v=j68OXAMlTM4 // https://leetcode.com/problems/reverse-pairs/discuss/97268/general-principles-behind-problems-similar-to-reverse-pairs // http://www.cnblo... 阅读全文
posted @ 2018-11-19 16:45 JTechRoad 阅读(151) 评论(0) 推荐(0)
摘要:class Solution { public: void merge(vector& nums1, int m, vector& nums2, int n) { int i = m + n - 1; m--; n--; while (m >= 0 && n >= 0) { if (nums1[m] > nums2[... 阅读全文
posted @ 2018-11-19 15:49 JTechRoad 阅读(56) 评论(0) 推荐(0)
摘要:class Solution { public: int maxProfit(vector& prices) { int res = 0; int low = INT_MAX; for (auto i : prices) { if (i res) res = i - low; ... 阅读全文
posted @ 2018-11-19 13:51 JTechRoad 阅读(80) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/two-sum/description/ 阅读全文
posted @ 2018-11-19 13:45 JTechRoad 阅读(89) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/linked-list-components/description/ 阅读全文
posted @ 2018-11-19 00:07 JTechRoad 阅读(82) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/jump-game-ii/description/ 阅读全文
posted @ 2018-11-18 16:39 JTechRoad 阅读(98) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/kth-largest-element-in-a-stream/description/ 阅读全文
posted @ 2018-11-18 13:57 JTechRoad 阅读(84) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/add-binary/description/ 阅读全文
posted @ 2018-11-18 13:36 JTechRoad 阅读(77) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/single-element-in-a-sorted-array/description/ 阅读全文
posted @ 2018-11-18 12:58 JTechRoad 阅读(130) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/decode-string/description/ 阅读全文
posted @ 2018-11-18 01:13 JTechRoad 阅读(103) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/unique-paths-ii/description/ 阅读全文
posted @ 2018-11-16 14:53 JTechRoad 阅读(85) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/trim-a-binary-search-tree/description/ 阅读全文
posted @ 2018-11-14 16:02 JTechRoad 阅读(61) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/top-k-frequent-words/description/ 阅读全文
posted @ 2018-11-14 14:06 JTechRoad 阅读(83) 评论(0) 推荐(0)
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ cla... 阅读全文
posted @ 2018-06-10 08:00 JTechRoad 阅读(101) 评论(0) 推荐(0)
摘要:class Solution { public: int maxProfit(vector& prices, int fee) { int n = prices.size(); if (n <= 1) return 0; // s0: max profit when not holding any stock // s1: max pro... 阅读全文
posted @ 2018-06-03 15:26 JTechRoad 阅读(80) 评论(0) 推荐(0)
摘要:class Solution { public: bool validPalindrome(string s) { int i = 0, j = s.length() - 1; while (i < j) { if (s[i] == s[j]) { i++; j--; ... 阅读全文
posted @ 2018-06-01 22:56 JTechRoad 阅读(135) 评论(0) 推荐(0)
摘要:class Solution { public: int findNumberOfLIS(vector& nums) { if (nums.size() == 0) return 0; pair res = {0, 0}; // vector> dp(nums.size(), {1,1}); // pair: length, cou... 阅读全文
posted @ 2018-06-01 15:56 JTechRoad 阅读(86) 评论(0) 推荐(0)
摘要:slow: faster: 阅读全文
posted @ 2018-06-01 15:55 JTechRoad 阅读(110) 评论(0) 推荐(0)