11 2018 档案

摘要:// Double points, or we can use DP (2 vectors to maintain left-max and right-max of each point.) class Solution { public: int trap(vector& height) { int res = 0, i = 0, j = height.size()-... 阅读全文
posted @ 2018-11-30 16:37 JTechRoad 阅读(88) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int res = (C-A) * (D-B) + (G-E) * (H-F); long x1 = max(A,E), y1 = max(B,F), x2 =... 阅读全文
posted @ 2018-11-30 15:44 JTechRoad 阅读(91) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector findErrorNums(vector& nums) { for (int i = 0; i ({nums[res], res+1}); } }; 阅读全文
posted @ 2018-11-30 15:16 JTechRoad 阅读(94) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: string reverseStr(string s, int k) { for (size_t i = 0; i < s.length(); i += 2 * k) { int start = i; int end = min(i+k, s.length()) - 1; ... 阅读全文
posted @ 2018-11-30 14:43 JTechRoad 阅读(102) 评论(0) 推荐(0) 编辑
摘要:huge perf improve from 1000+ ms to 300 ms: 阅读全文
posted @ 2018-11-29 23:39 JTechRoad 阅读(116) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int countBattleships(vector>& board) { int res = 0; for (int i = 0; i 0 && board[i-1][j] == 'X' || j > 0 && board[i][j-1] == 'X') ... 阅读全文
posted @ 2018-11-27 17:03 JTechRoad 阅读(73) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int kthGrammar(int N, int K) { return helper(N, K, false); } int helper(int n, int k, bool reverse) { if (n == 1) return reverse; int tota... 阅读全文
posted @ 2018-11-27 05:42 JTechRoad 阅读(97) 评论(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-11-27 05:33 JTechRoad 阅读(91) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector fizzBuzz(int n) { vector res; for (int i = 1; i <= n; i++) { if (i % 3 == 0 && i % 5 == 0) res.push_back("FizzBuzz"); ... 阅读全文
posted @ 2018-11-24 16:53 JTechRoad 阅读(107) 评论(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-11-24 16:40 JTechRoad 阅读(52) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int majorityElement(vector& nums) { int m = 0, c = 0; for (auto i : nums) { if (c == 0) { m = i; c++; ... 阅读全文
posted @ 2018-11-24 16:36 JTechRoad 阅读(76) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* d... 阅读全文
posted @ 2018-11-24 15:44 JTechRoad 阅读(56) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int maximalRectangle(vector>& matrix) { int m = matrix.size(); if (m == 0) return 0; int n = matrix[0].size(); if (n == 0) return 0; vector> v(m,... 阅读全文
posted @ 2018-11-24 15:27 JTechRoad 阅读(85) 评论(0) 推荐(0) 编辑
摘要:// Forward declaration of isBadVersion API. bool isBadVersion(int version); class Solution { public: int firstBadVersion(int n) { int i = 1, j = n; while (i< j - 1) { ... 阅读全文
posted @ 2018-11-24 13:57 JTechRoad 阅读(81) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: bool PredictTheWinner(vector& nums) { return helper(nums, 0, nums.size()-1, true, 0, 0); } // return true if player1 can win. false if player1 will lose. ... 阅读全文
posted @ 2018-11-23 16:35 JTechRoad 阅读(120) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector> findLadders(string beginWord, string endWord, vector& wordList) { unordered_set s(wordList.begin(), wordList.end()); vector> res; if (s.fi... 阅读全文
posted @ 2018-11-23 15:07 JTechRoad 阅读(165) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int ladderLength(string beginWord, string endWord, vector& wordList) { unordered_set s(wordList.begin(), wordList.end()); if (s.find(endWord) == s.end() |... 阅读全文
posted @ 2018-11-22 08:21 JTechRoad 阅读(105) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int rob(vector& nums) { if (nums.size() == 0) return 0; if (nums.size() == 1) return nums[0]; return max(helper(nums, 0, nums.size()-2), helpe... 阅读全文
posted @ 2018-11-22 07:40 JTechRoad 阅读(88) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int largestRectangleArea(vector& h) { stack s; int res = 0; h.push_back(0); for (int i = 0; i < h.size(); i++) { while (!s.emp... 阅读全文
posted @ 2018-11-22 06:40 JTechRoad 阅读(81) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int numRescueBoats(vector& people, int limit) { sort(people.begin(), people.end()); int res = 0; for (int i = 0, j = people.size()-1; i <= j; ) { ... 阅读全文
posted @ 2018-11-22 06:12 JTechRoad 阅读(93) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* s... 阅读全文
posted @ 2018-11-22 02:29 JTechRoad 阅读(119) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector> largeGroupPositions(string s) { vector> res; int start = 0, end = 0; for (int i = 1; i = 3) { vector t; ... 阅读全文
posted @ 2018-11-21 15:28 JTechRoad 阅读(87) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int numSquares(int n) { vector c; for (int i = 1; i*i q; q.push(0); int lv = 0; while (!q.empty()) { int qs = q.size(... 阅读全文
posted @ 2018-11-21 15:09 JTechRoad 阅读(74) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector> threeSum(vector& nums) { sort(nums.begin(), nums.end()); vector> res; if (nums.size() 0 && nums[i] == nums[i-1]) continue; i... 阅读全文
posted @ 2018-11-21 14:06 JTechRoad 阅读(95) 评论(0) 推荐(0) 编辑
摘要:/* // Definition for a Node. class Node { public: int val = NULL; Node* prev = NULL; Node* next = NULL; Node* child = NULL; Node() {} Node(int _val, Node* _prev, Node* _next... 阅读全文
posted @ 2018-11-20 14:54 JTechRoad 阅读(81) 评论(0) 推荐(0) 编辑
摘要: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 阅读(98) 评论(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 阅读(155) 评论(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 阅读(146) 评论(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 阅读(50) 评论(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 阅读(75) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/two-sum/description/ 阅读全文
posted @ 2018-11-19 13:45 JTechRoad 阅读(80) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/linked-list-components/description/ 阅读全文
posted @ 2018-11-19 00:07 JTechRoad 阅读(76) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/jump-game-ii/description/ 阅读全文
posted @ 2018-11-18 16:39 JTechRoad 阅读(83) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/kth-largest-element-in-a-stream/description/ 阅读全文
posted @ 2018-11-18 13:57 JTechRoad 阅读(75) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/add-binary/description/ 阅读全文
posted @ 2018-11-18 13:36 JTechRoad 阅读(74) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/single-element-in-a-sorted-array/description/ 阅读全文
posted @ 2018-11-18 12:58 JTechRoad 阅读(126) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/decode-string/description/ 阅读全文
posted @ 2018-11-18 01:13 JTechRoad 阅读(97) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/unique-paths-ii/description/ 阅读全文
posted @ 2018-11-16 14:53 JTechRoad 阅读(75) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/trim-a-binary-search-tree/description/ 阅读全文
posted @ 2018-11-14 16:02 JTechRoad 阅读(52) 评论(0) 推荐(0) 编辑
摘要:https://leetcode.com/problems/top-k-frequent-words/description/ 阅读全文
posted @ 2018-11-14 14:06 JTechRoad 阅读(74) 评论(0) 推荐(0) 编辑