随笔分类 -  Leetcode

摘要:class Solution { public: vector res; vector addOperators(string num, int target) { if (num.length() == 0) return res; helper(num, target, "", 0, 0, 0); return res; ... 阅读全文
posted @ 2018-05-22 15:05 JTechRoad 阅读(99) 评论(0) 推荐(0)
摘要:class Solution { public: int hIndex(vector& citations) { if (citations.size() == 0) return 0; int i = 0, j = citations.size(); while (i citations[pos]) j... 阅读全文
posted @ 2018-05-22 14:30 JTechRoad 阅读(76) 评论(0) 推荐(0)
摘要:class Solution { public: int hIndex(vector& citations) { int n = citations.size(); vector buck(n+1, 0); for (auto c : citations) { if (c > n) c... 阅读全文
posted @ 2018-05-22 13:37 JTechRoad 阅读(82) 评论(0) 推荐(0)
摘要:class Solution { public: vector productExceptSelf(vector& nums) { if (nums.size() == 0) return vector(); vector res(nums.size(), 1); for (int i = 1; i = 0; i--) { ... 阅读全文
posted @ 2018-05-22 07:42 JTechRoad 阅读(69) 评论(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-05-22 07:33 JTechRoad 阅读(65) 评论(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-05-22 07:27 JTechRoad 阅读(61) 评论(0) 推荐(0)
摘要:Recurision, TLE. DP: 阅读全文
posted @ 2018-05-22 02:58 JTechRoad 阅读(136) 评论(0) 推荐(0)
摘要:class Solution { public: int maximalSquare(vector>& matrix) { int m = matrix.size(); if (m == 0) return 0; int n = matrix[0].size(); if (n == 0) return 0; vector> dp(m+1,... 阅读全文
posted @ 2018-05-21 22:28 JTechRoad 阅读(127) 评论(0) 推荐(0)
摘要:class Solution { public: vector> getSkyline(vector>& buildings) { vector> v; for (const auto& b : buildings) { v.push_back({b[0], -b[2]}); v.push_back({b[1... 阅读全文
posted @ 2018-05-21 21:13 JTechRoad 阅读(80) 评论(0) 推荐(0)
摘要:class Solution { public: int findKthLargest(vector& nums, int k) { int left = 0, right = nums.size() - 1; while (true) { int p = partition(nums, left, right); ... 阅读全文
posted @ 2018-05-21 14:23 JTechRoad 阅读(92) 评论(0) 推荐(0)
摘要:class Solution { public: int minSubArrayLen(int s, vector& nums) { int w = 0, _sum = 0, res = INT_MAX; for (int i = 0; i = s) { res = min(res, i-w+1); ... 阅读全文
posted @ 2018-05-21 12:05 JTechRoad 阅读(65) 评论(0) 推荐(0)
摘要:class Node { public: char c; bool isWord; unordered_map children; Node(char c) { this->c = c; isWord = false; } }; class Trie { Node* root; Node* find... 阅读全文
posted @ 2018-05-21 09:23 JTechRoad 阅读(89) 评论(0) 推荐(0)
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class BSTIt... 阅读全文
posted @ 2018-05-21 09:00 JTechRoad 阅读(80) 评论(0) 推荐(0)
摘要:class LRUCache { public: list> q; unordered_map>::iterator> m; int cap; LRUCache(int capacity) { cap = capacity; } int get(int key) { if (!m.count(key)) ... 阅读全文
posted @ 2018-05-21 08:45 JTechRoad 阅读(85) 评论(0) 推荐(0)
摘要:class Solution { public: bool wordBreak(string s, vector& wordDict) { int n = s.length(); if (n == 0) return false; unordered_set wordSet(wordDict.begin(), wordDict.end()); ... 阅读全文
posted @ 2018-05-21 00:57 JTechRoad 阅读(79) 评论(0) 推荐(0)
摘要:/** * Definition for undirected graph. * struct UndirectedGraphNode { * int label; * vector neighbors; * UndirectedGraphNode(int x) : label(x) {}; * }; */ class Solution { public: ... 阅读全文
posted @ 2018-05-20 15:23 JTechRoad 阅读(84) 评论(0) 推荐(0)
摘要:class Solution { public: int longestConsecutive(vector& nums) { unordered_set s(nums.begin(), nums.end()); int res = 0; while (!s.empty()) { int p = *(s.begin(... 阅读全文
posted @ 2018-05-20 14:34 JTechRoad 阅读(87) 评论(0) 推荐(0)
摘要:class Solution { public: int ladderLength(string beginWord, string endWord, vector& wordList) { unordered_set s(wordList.begin(), wordList.end()); if (!s.count(endWord)) return 0... 阅读全文
posted @ 2018-05-20 14:27 JTechRoad 阅读(80) 评论(0) 推荐(0)
摘要:class Solution { public: bool isPalindrome(string s) { int i = 0, j = s.length() - 1; while (i < j) { if (!isalnum(s[i])) i++; else if (!is... 阅读全文
posted @ 2018-05-20 14:16 JTechRoad 阅读(72) 评论(0) 推荐(0)
摘要:/** * Definition for binary tree with next pointer. * struct TreeLinkNode { * int val; * TreeLinkNode *left, *right, *next; * TreeLinkNode(int x) : val(x), left(NULL), right(NULL), next(NULL)... 阅读全文
posted @ 2018-05-20 13:43 JTechRoad 阅读(106) 评论(0) 推荐(0)