![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
文章平均质量分 77
gunxueqiucjw
这个作者很懒,什么都没留下…
展开
-
leetcode Min stack
It is very easy to get idea of this problem. Just use an auxiliary stack (s_a) to store the current minimum element in the data stack (s_d). But leetcode has a strong constrain in the memory size, alw原创 2014-11-11 02:53:15 · 621 阅读 · 0 评论 -
leetcode surronded region
#include #include #include using namespace std;class Solution {public: int** visited; int *circle_r, *circle_c; int st, ed, row, col; void solve(vector > &board) { int原创 2015-01-04 01:24:25 · 720 阅读 · 0 评论 -
leetcode word break I && II
Two dynamic programming problemproblem II can use the code of problem IWord Break Iclass Solution {public: int longestWord(unordered_set dict) { unordered_set::iterator it;原创 2015-01-02 16:13:05 · 762 阅读 · 0 评论 -
leetcode Palindrome I and II comparison
The easier one "Palindrome I" is solved by DFS ALG1. From left to right, judge the substr(0, i) is Palindrome or not. If it is, add it to one of the element of the answer. Then use partition to find原创 2015-01-02 09:58:08 · 505 阅读 · 0 评论 -
leetcode Unique BST
总结一下这题:碰到这种计数问题应该本能想到用dynamic programming的思路又正好是关于tree的问题,所以应该先想到左子树的结果与右子树的结果的某种操作,这道题正好应该选择乘法操作class Solution {public: // DFS method int *lookup; int numTrees(int n) { // re原创 2014-12-23 14:11:35 · 582 阅读 · 0 评论 -
leetcode Majority Element
这题限制时间复杂度是O(n) 才能通过所有测试,之前写了一个现sorting的,复杂度是O(nlogn),Time Limited Exceed!!!网上看到一个很赞的算法Moore voting algorithm, Stackoverflow 上有很好的解释class Solution {public: int majorityElement(vector &nu原创 2014-12-23 08:19:40 · 901 阅读 · 0 评论 -
leetcode validate binary search tree
一道Easy级别的题目Given a binary tree, determine if it is a valid binary search tree (BST).Assume a BST is defined as follows:The left subtree of a node contains only nodes with keys less than原创 2014-12-23 09:16:54 · 538 阅读 · 0 评论 -
leetcode Binary Tree Upside Down
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */ class So原创 2014-12-22 14:00:19 · 719 阅读 · 0 评论 -
LRU leetcode 代码实现
很奇怪,我自己明明能跑得通的程序放在leetcode上面测试会出现Runtime原创 2014-04-21 01:46:21 · 963 阅读 · 1 评论 -
leetcode Read N Characters Given Read4
// Forward declaration of the read4 API.int read4(char *buf);class Solution {public: /** * @param buf Destination buffer * @param n Maximum number of characters to read * @ret原创 2014-12-22 13:51:47 · 1009 阅读 · 0 评论 -
leetcode Find minimum in rotated sorted array
Just the following code for both duplicated or not.原创 2014-11-12 07:02:41 · 637 阅读 · 0 评论 -
leetcode sum from root to leaf
Just the code. This is a very easy one. Using DFS ALG/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : va原创 2015-01-04 01:27:21 · 517 阅读 · 0 评论