- 博客(20)
- 收藏
- 关注
原创 leetcode-第十九周
539. Minimum Time Differenceclass Solution {private: int toInt(const string &s) { char c; int h, m; stringstream ss(s); ss >> h >> c >> m; return h * 60 + m; }
2017-07-03 20:00:53
246
原创 leetcode-第十八周
617. Merge Two Binary Trees/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), rig
2017-06-22 19:43:42
178
原创 课本NP-complete证明题
8.3给定方程式f,令(f,k)表示k个变量的SAT问题的实例,下面证明一组赋值a是f的解当且仅当a也是(f,k)的解。 必要性:假设a是f的解,因为一共有k个变量,所以a中也有不超过k个变量为真,所以a也是(f,k)的解。 充分性:假设a是(f,k)的解,那么显然也是对应f的解。
2017-06-12 22:47:38
247
原创 leetcode-第十七周
445. Add Two Numbers II/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {pr
2017-06-12 22:07:35
185
原创 leetcode-第十六周
295. Find Median from Data Stream/** * 维护两个堆,可以用priority_queue, multiset * 大顶堆维护小的数值 * 小顶堆维护大的数值 */class MedianFinder {private: priority_queue<int, vector<int>, less<int> > mn; prior
2017-06-08 13:31:12
239
原创 leetcode-第十五周
329. Longest Increasing Path in a Matrixclass Solution {private: typedef vector<int> VI; typedef vector<VI> VVI; int dfs(VVI &dp, VVI &A, int x, int y) { if (dp[x][y] != -1) return
2017-06-03 15:22:38
190
原创 leetcode-第十四周
17. Letter Combinations of a Phone Number/** * Time: O(4 ^ n) * Space: O(n) * 思路:深搜暴力求解 */class Solution {private: void dfs(const string &digits, int pos, vector<string> &ret, string ¤t
2017-05-25 16:00:14
144
原创 leetcode-第十三周
304. Range Sum Query 2D - Immutableclass NumMatrix {private: vector<vector<int> > pre; int mm, nn;public: NumMatrix(vector<vector<int>> &matrix) { mm = matrix.size(); if (
2017-05-16 14:12:52
187
原创 leetcode-第十二周
331. Verify Preorder Serialization of a Binary Treeclass Solution {private: vector<string> getT(string preorder) { vector<string> ret; preorder += ","; for (int i = 0; i <
2017-05-11 11:56:46
163
原创 leetcode-第十一周
239. Sliding Window Maximumclass Solution {public: vector<int> maxSlidingWindow(vector<int>& nums, int k) { deque<int> q; vector<int> ret; for (int i = 0; i < nums.size();
2017-05-04 11:58:29
169
原创 leetcode-第十周
39. Combination Sumclass Solution {private: vector<vector<int>> ret; vector<int> tmp;public: void solve(vector<int>& arr, int start, int target) { if (target == 0) { v
2017-04-24 09:47:09
214
原创 leetcode-第九周
186. Reverse Words in a String IIclass Solution {public: void reverseWords(string &s) { reverse(s.begin(), s.end()); for (int i = 0, j = 0; j <= s.size(); j++) { if (j
2017-04-17 17:19:13
211
原创 leetcode-第八周
50. Pow(x, n)Implement pow(x, n)./*** 思路:二分,注意要考虑:* 1. n为负数* 2. x为0*/class Solution {private: const double EPS = 1e-10;public: double myPow(double x, int n) {
2017-04-11 17:38:55
212
原创 leetcode-第七周
257. Binary Tree Paths/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NU
2017-04-06 09:45:39
154
原创 leetcode-第六周
33. Search in Rotated Sorted Array/** * 思路:二分查找,闭区间 * 三种case: * 1. A[l] <= A[r] * 2. A[l] > A[r] && A[l] < A[mid] * 3. A[l] > A[r] && A[mid] < A[r] */class Solution {public: int search(vect
2017-03-28 16:57:54
242
原创 leetcode-第五周
42. Trapping Rain WaterGiven n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap after raining.For example, Given [0,1,0,
2017-03-21 13:52:47
189
原创 leetcode-第四周
126. Word Ladder IIGiven two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, such that:Only one letter can be change
2017-03-15 09:52:48
211
原创 leetcode-第三周
513. Find Bottom Left Tree ValueGiven a binary tree, find the leftmost value in the last row of the tree.Example: Input: 1 / \ 2 3 / / \4 5 6 / 7Output: 7 Note: You may assu
2017-03-07 15:29:23
239
原创 leetcode-第二周
135. CandyThere are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following requirements:Each child must
2017-02-28 19:24:11
152
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人