
leetcode
文章平均质量分 62
markpen
这个作者很懒,什么都没留下…
展开
-
Leetcode Wiggle Sort II
leetcode 324 wiggle sort II原创 2016-07-29 21:35:02 · 233 阅读 · 0 评论 -
Leetcode Kth Largest Element in an Array
Leetcode 215 Kth Largest Element in an Array原创 2016-07-29 21:42:50 · 185 阅读 · 0 评论 -
Leetcode Single Number III
Leetcode 260 SIngle Number III原创 2016-07-29 21:54:12 · 212 阅读 · 0 评论 -
Leetcode Counting Bits
Leetcode 338 Counting Bits原创 2016-07-29 21:59:17 · 201 阅读 · 0 评论 -
Leetcode Game of Life
Leetcode 289 Game of Life原创 2016-07-29 22:09:39 · 265 阅读 · 0 评论 -
Leetcode Set Matrix Zores
Leetcode 73 Set Matrix Zeros原创 2016-07-29 22:35:13 · 461 阅读 · 0 评论 -
Leetcode Find Peak Element
Leetcode162 Find Peak Element原创 2016-07-29 22:44:22 · 216 阅读 · 0 评论 -
Leetcode Pascal's Triangle II
Leetcode 119 Pascal's Triangle II原创 2016-07-30 13:49:29 · 264 阅读 · 0 评论 -
leetcode Course Schedule
Leetcode 207 Course Schedule原创 2016-08-02 20:26:08 · 230 阅读 · 0 评论 -
leetcode Number of Islands
Leetcode 200 Number of Islands原创 2016-08-10 17:58:00 · 275 阅读 · 0 评论 -
Leetcode H-Index
Leetcode 274 H-Index原创 2016-08-10 21:00:49 · 243 阅读 · 0 评论 -
Leetcode H-Index II
Leetcode 275 H-Index II原创 2016-08-10 21:26:50 · 196 阅读 · 0 评论 -
Leetcode Ransom Note
leetcode 383 Ransom Note原创 2016-08-12 22:30:38 · 796 阅读 · 0 评论 -
Leetcode Maximum Depth of Binary Tree
Leetcode 104 Maximum Depth of Binary Tree原创 2016-08-12 22:52:55 · 185 阅读 · 0 评论 -
Leetcode Invert Binary Tree
Leetcode 226 Invert Binary Tree原创 2016-08-12 23:01:52 · 187 阅读 · 0 评论 -
Leetcode Remove Duplicates from Sorted List
Leetcode 83 Remove Duplicates from Sorted List原创 2016-08-12 23:36:42 · 186 阅读 · 0 评论 -
Leetcode Maximum Subarray
Leetcode 53 Maximum Subarray原创 2016-08-13 11:35:10 · 209 阅读 · 0 评论 -
Leetcode Gray Code
Leetcode 89 Gray Code原创 2016-08-13 14:42:13 · 223 阅读 · 0 评论 -
Leetcode Balanced Binary Tree
题意:判断一棵树是否为平衡树。平衡树是指,各子树的高度之差不超过1。思路:计算各子树高度,并判断。class Solution {public: bool isBalanced(TreeNode* root) { if(!root) return true; bool bleft = false; bool bright = fal原创 2016-12-18 03:26:17 · 182 阅读 · 0 评论 -
Leetcode 2
listclass Solution {public: ListNode* addTwoNumbers(ListNode* l1, ListNode* l2) { ListNode *temp1 = l1; ListNode *temp2 = l2; ListNode *head = new ListNode(0); head->nex原创 2016-12-14 12:28:29 · 222 阅读 · 0 评论 -
Leetcode 17
题意:输入数字,找所以可能的字母组合。思路:DFS,到达叶结点输出。class Solution {public: vector b; vector re; vector letterCombinations(string digits) { string s = "abc"; b.push_back(s); s = "def";原创 2016-12-17 02:49:32 · 331 阅读 · 0 评论 -
Leetcode Valid Parentheses
题意:括号匹配。思路:堆栈。class Solution {public: bool isValid(string s) { stack mys; mys.push(s[0]); for(unsigned i = 1; i < s.length(); ++ i) { if(!mys.empty()) {原创 2016-12-17 03:32:06 · 233 阅读 · 0 评论 -
Leetcode Merge Two Sorted Lists
题意:合并两个排列好的队列。思路:列表的基本操作。class Solution {public: ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) { ListNode *nextl1 = l1; ListNode *nextl2 = l2; ListNode原创 2016-12-17 03:49:19 · 194 阅读 · 0 评论 -
Leetcode Generate Parentheses
题意:写出所有合法的括号组合。思路:DFS。class Solution {public: vector re; vector generateParenthesis(int n) { string s = ""; dfs(s, n, n); return re; } int dfs(str原创 2016-12-17 07:09:45 · 229 阅读 · 0 评论 -
Leetcode Valid Sudoku
题意:检查数独是否合法,行列及九宫格的数字 不能重复。思路:暴力检查。class Solution {public: bool isValidSudoku(vector>& board) { bool isRepeat[10]; for(int i = 0; i < board.size(); ++ i) {原创 2016-12-17 08:18:26 · 197 阅读 · 0 评论 -
Leetcode Plus One
题意:整数加一。思路:模拟题。class Solution {public: vector plusOne(vector& digits) { vector re; int c = 0; for(int i = digits.size(); i > 0; -- i) { int d = digits[i -原创 2016-12-17 12:34:17 · 213 阅读 · 0 评论 -
Leetcode Same Tree
题意:判断两棵树是否相等。思路:DFS。class Solution {public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL && q == NULL) return true; if(p == NULL && q != NULL) return false;原创 2016-12-17 12:51:30 · 199 阅读 · 0 评论 -
Leetcode Minimum Path Sum
题意:只能向下或者向右,求路径最短。思路:简单DP。class Solution {public: int minPathSum(vector>& grid) { int m = grid.size(); int n = grid[0].size(); vector > dis = grid; fo原创 2016-12-17 14:47:32 · 206 阅读 · 0 评论 -
Leetcode Path Sum
题意:判断是否存在从根结点到叶结点,路上结点之和为所给的值的路径。思路:DFS。class Solution {public: bool hasPathSum(TreeNode* root, int sum) { if(root == NULL) return false; sum -= root->val; bo原创 2016-12-17 15:34:44 · 295 阅读 · 0 评论 -
Leetcode Submission Details
题意:找树最浅的深度。思路:DFS。class Solution {public: int minDepth(TreeNode* root) { if(root == NULL) return 0; if(root->left == NULL && root->right == NULL) return 1; int deeplef原创 2016-12-17 15:44:24 · 283 阅读 · 0 评论 -
Leetcode Basic Calculator
题意:编写一个基本的计算器,实现加减法操作。思路:用堆栈完成优先级操作。class Solution {public: int calculate(string s) { stack cal; for(int i = 0; i < s.length(); ++ i) { if(s[i] == ' ') continue;原创 2016-12-21 11:46:11 · 202 阅读 · 0 评论 -
Leetcode Insertion Sort List
题意:用链表实现插入排序。思路:简单模拟,注意处理链表的开头与结尾。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */cla原创 2016-12-22 01:46:12 · 204 阅读 · 0 评论 -
Leetcode Binary Tree Maximum Path Sum
题意:找到一棵树中,各结点值和最大的路径。思路:DFS, 返回必须经过该结点的路径的最大值和可能经过该结点的路径的最大值。/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * Tr原创 2016-12-22 03:35:25 · 323 阅读 · 0 评论 -
Leetcode Trapping Rain Water
题意:给出地形的高度,求出能汇集的最多的雨水。思路:这题和什么时候买股票那题有点像。数组lr记录到目前为止,左边的最高高度;数组rl记录到目前为止,右边的最高高度。他们的最小值就是能汇集的水量。class Solution {public: int trap(vector& height) { if(height.size() <= 1) return 0;原创 2016-12-22 05:44:52 · 271 阅读 · 0 评论 -
Leetcode Longest Increasing Path in a Matrix
题意:在矩阵中找最大递增路径。思路:DFS。向可能的四个方向搜索,将返回的最大值 + 1作为该结点的值。class Solution {public: vector > m; int xx,yy; vector > mmatrix; int longestIncreasingPath(vector>& matrix) { if(matrix原创 2016-12-22 09:22:15 · 263 阅读 · 0 评论 -
Leetcode Sort Characters By Frequency
题意:按字符出现频率降序输出字符。思路:用hash实现O(1)插入和查找。class Solution {public: string frequencySort(string s) { map m; for(int i = 0; i < s.length(); ++ i) { m[s[i]] ++; }原创 2016-12-22 11:28:41 · 266 阅读 · 0 评论 -
Leetcode Range Sum Query - Immutable
题意:给出一数组,求i到j之间的和。题意:记录开始位置到各位置的和,查询时,减去开头部分的和。class NumArray {public: NumArray(vector &nums) { totalSum.push_back(0); int sum = 0; for(int i = 0; i < nums.size(); ++原创 2017-01-02 01:26:36 · 211 阅读 · 0 评论 -
Leetcode Remove Nth Node From End of List
题意:删除链表中倒数第i个元素。思路:用堆栈完成计数工作。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class So原创 2017-01-02 01:57:05 · 245 阅读 · 0 评论 -
Leetcode Longest Palindromic Substring
题意:求最长回文子串。思路:记录到目前为止,以该字母结尾的所有字串的起始位置,之后的字符遍历这些长度,记录更新后的起始位置。class Solution {public: string longestPalindrome(string s) { vector > pal; vector temp(1, 0); pal.push_ba原创 2016-12-22 14:25:11 · 201 阅读 · 0 评论 -
Leetcode Number of Boomerangs
题意:求一个平面中,一个点到其他两个点的距离相等的点,这样的点一共有多少组。思路:求出所有两两点之间的距离,用hash统计距离相同的点。class Solution {public: int numberOfBoomerangs(vector>& points) { vector > distance; for(int i = 0原创 2017-01-03 05:43:37 · 304 阅读 · 0 评论