随笔分类 - 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; ...
阅读全文
摘要:class Solution { public: int hIndex(vector& citations) { if (citations.size() == 0) return 0; int i = 0, j = citations.size(); while (i citations[pos]) j...
阅读全文
摘要:class Solution { public: int hIndex(vector& citations) { int n = citations.size(); vector buck(n+1, 0); for (auto c : citations) { if (c > n) c...
阅读全文
摘要: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--) { ...
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ cla...
阅读全文
摘要:/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ cla...
阅读全文
摘要:Recurision, TLE. DP:
阅读全文
摘要: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,...
阅读全文
摘要: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...
阅读全文
摘要:class Solution { public: int findKthLargest(vector& nums, int k) { int left = 0, right = nums.size() - 1; while (true) { int p = partition(nums, left, right); ...
阅读全文
摘要: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); ...
阅读全文
摘要:class Node { public: char c; bool isWord; unordered_map children; Node(char c) { this->c = c; isWord = false; } }; class Trie { Node* root; Node* find...
阅读全文
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class BSTIt...
阅读全文
摘要:class LRUCache { public: list> q; unordered_map>::iterator> m; int cap; LRUCache(int capacity) { cap = capacity; } int get(int key) { if (!m.count(key)) ...
阅读全文
摘要: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()); ...
阅读全文
摘要:/** * Definition for undirected graph. * struct UndirectedGraphNode { * int label; * vector neighbors; * UndirectedGraphNode(int x) : label(x) {}; * }; */ class Solution { public: ...
阅读全文
摘要:class Solution { public: int longestConsecutive(vector& nums) { unordered_set s(nums.begin(), nums.end()); int res = 0; while (!s.empty()) { int p = *(s.begin(...
阅读全文
摘要:class Solution { public: int ladderLength(string beginWord, string endWord, vector& wordList) { unordered_set s(wordList.begin(), wordList.end()); if (!s.count(endWord)) return 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...
阅读全文
摘要:/** * 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)...
阅读全文
浙公网安备 33010602011771号