随笔分类 -  Leetcode

1 2 3 4 5 ··· 8 下一页
摘要:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ class Solution { public: ListNode* m... 阅读全文
posted @ 2018-12-08 15:24 JTechRoad 阅读(104) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector res; vector findAllConcatenatedWordsInADict(vector& words) { unordered_set s(words.begin(), words.end()); for (auto & w : words) if... 阅读全文
posted @ 2018-12-08 15:20 JTechRoad 阅读(97) 评论(0) 推荐(0) 编辑
摘要:// O(nlogn) class Solution { public: int lengthOfLIS(vector& nums) { int n = nums.size(); if (n dp; dp.push_back(nums[0]); for (int i = 1; i & nums) { int n = num... 阅读全文
posted @ 2018-12-08 14:25 JTechRoad 阅读(86) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector> res; int m, n; vector> updateMatrix(vector>& matrix) { m = matrix.size(); if (m == 0) return res; n = matrix[0].size(); if (n==0) return ... 阅读全文
posted @ 2018-12-06 16:04 JTechRoad 阅读(170) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int maxDistToClosest(vector& seats) { int first = 0, last = seats.size() - 1; while (seats[first] == 0) first++; while (seats[last] == 0) las... 阅读全文
posted @ 2018-12-05 04:26 JTechRoad 阅读(82) 评论(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-12-04 15:56 JTechRoad 阅读(184) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: string convertToBase7(int num) { if (num == 0) return "0"; long n = abs(num); int flag = num > 0 ? 1 : -1; string res;... 阅读全文
posted @ 2018-12-04 01:13 JTechRoad 阅读(121) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int maxSubArray(vector& nums) { int res = nums[0], cur = nums[0]; for (int i = 1; i < nums.size(); i++) { cur = max(cur, 0) + nums[i]; ... 阅读全文
posted @ 2018-12-03 17:10 JTechRoad 阅读(86) 评论(0) 推荐(0) 编辑
摘要:// improvement: // 1) convert unordered_map to 26 bitmap (done) // 2) for each step in dfs, we don't have search the word from beginning in trie, // we can actually search from previous node. shou... 阅读全文
posted @ 2018-12-03 15:37 JTechRoad 阅读(144) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int m, n; bool exist(vector>& board, string word) { m = board.size(); if (m == 0) return false; n = board[0].size(); if (n == 0) return false; ... 阅读全文
posted @ 2018-12-03 14:16 JTechRoad 阅读(149) 评论(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-12-03 13:43 JTechRoad 阅读(73) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: vector path; unordered_map> m; vector findItinerary(vector> tickets) { for (auto &p : tickets) m[p.first].insert(p.second); dfs("JFK")... 阅读全文
posted @ 2018-12-02 07:41 JTechRoad 阅读(91) 评论(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-12-02 07:40 JTechRoad 阅读(70) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: int calPoints(vector& ops) { vector v; for (auto &s : ops) { if (s == "+") { v.push_back(v[v.size()-1] + v[v.size()-2]); ... 阅读全文
posted @ 2018-12-01 17:06 JTechRoad 阅读(84) 评论(0) 推荐(0) 编辑
摘要:class Solution { public: string solveEquation(string equation) { int idx = equation.find('='); int x1 = 0, v1 = 0, x2 = 0, v2 = 0, idx1 = 0, idx2 = 0; helper(equa... 阅读全文
posted @ 2018-12-01 15:07 JTechRoad 阅读(97) 评论(0) 推荐(0) 编辑
摘要:// 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 阅读(95) 评论(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 阅读(118) 评论(0) 推荐(0) 编辑

1 2 3 4 5 ··· 8 下一页
点击右上角即可分享
微信分享提示