
Leetcode
jason_mai
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
4. Median of Two Sorted Arrays
题目链接https://leetcode.com/problems/median-of-two-sorted-arrays/description/ 题目描述 There are two sorted arraysnums1andnums2of size m and n respectively. Find the median of the two sorted ...原创 2018-04-28 09:27:02 · 138 阅读 · 0 评论 -
115. Distinct Subsequences
115. Distinct Subsequences 题目来源 https://leetcode.com/problems/distinct-subsequences/ 题意分析 给定字符串S跟字符串T,求字符串S中能构成T的子串的数目,字符串的子串指删除字符串特定字符后形成的字符串 例子 Example 1: Input: S = “rabbbit”, T = “rabbit” Output: ...原创 2019-11-14 18:18:03 · 131 阅读 · 0 评论 -
94. Binary Tree Inorder Traversal
#94. Binary Tree Inorder Traversal题目来源:https://leetcode.com/problems/binary-tree-inorder-traversal/description/题意分析:用迭代的方式求出树的中序遍历。思路:维护这样的一个栈:栈元素为指向树节点的指针,对于这个栈里的每个元素node,保证node->left在node的顶层(先访问)...原创 2018-06-11 10:38:18 · 155 阅读 · 0 评论 -
92. Reverse Linked List II
#92. Reverse Linked List II92. Reverse Linked List题目来源:https://leetcode.com/problems/reverse-linked-list-ii/description/题意分析:给定区间[m,n]和单向链表表头,把链表第m个---第n个元素reverse例子:代码:发现了一个可以加速cin,cout输出的万用函数hhh/** ...原创 2018-06-07 13:23:04 · 149 阅读 · 0 评论 -
206. Reverse Linked List
#206. Reverse Linked List题目来源:https://leetcode.com/problems/reverse-linked-list/description/题意分析:reverse一个单向链表,用迭代跟递归两种方式。例子:代码: 递归方式class Solution { public: ListNode* reverseList(ListNode* hea...原创 2018-06-07 12:10:56 · 164 阅读 · 0 评论 -
639. Decode Ways II
#639. Decode Ways II题目来源:https://leetcode.com/problems/decode-ways-ii/description/题意分析:存在一个映射把"A"-"Z"映射到1-26。给定一串包含数字喝和"*"的字符串,'*'可以表示1-9的任意数字。求出解码为字母的方式的数目。返回结果对10^9+7取余。hint:这题是#91. Decode Ways的延伸,建...原创 2018-06-07 00:12:41 · 438 阅读 · 0 评论 -
89. Gray Code
#89. Gray Code(枚举格雷码)题目来源:https://leetcode.com/problems/gray-code/description/题意分析:给定n,枚举出所有长度为n的格雷码的十进制表示。 例子:题目思路:相当于实现二进制到格雷码的转换。class Solution { public: vector<int> grayCode(int n) { ...原创 2018-06-06 18:42:01 · 559 阅读 · 0 评论 -
84. Largest Rectangle in Histogram
#84. Largest Rectangle in Histogram(求矩形最大面积)题目来源:https://leetcode.com/problems/largest-rectangle-in-histogram/description/题意分析:给一个正整数列表,每个数字x在直方图上表示宽度为1的矩形的高度,求直方图中的最大矩形。 题目思路:最大矩形的高是由组成矩形的小矩形的最小高度决定的...原创 2018-06-06 11:36:44 · 572 阅读 · 0 评论 -
23. Merge k Sorted Lists
# 23. Merge k Sorted Lists题目来源:https://leetcode.com/problems/merge-k-sorted-lists/description/ 题意分析:合并K个有序链表为一个有序链表 Example:Input:[ 1->4->5, 1->3->4, 2->6]Output: 1->1->2->3...原创 2018-05-09 23:28:49 · 150 阅读 · 0 评论 -
215 Kth Largest Element in an Array
# 215 Kth Largest Element in an Array题目来源:https://leetcode.com/problems/kth-largest-element-in-an-array/description/ 题意分析:在一个无序链表中找出第k大的元素。Example 1:Input: [3,2,1,5,6,4] and k = 2Output: 5Example 2:In...原创 2018-05-09 23:24:27 · 175 阅读 · 0 评论 -
148 Sort List
# 148 Sort List题目来源:https://leetcode.com/problems/sort-list/description/题意分析:Sort a linked list in O(n log n) time using constant space complexity.对一个链表进行排序,时间复杂度为O(n log n) ,空间复杂度为常量。题目思路:学了python之后,...原创 2018-05-09 23:23:40 · 153 阅读 · 0 评论 -
134 Gas Station
# 134 Gas Station题目来源: https://leetcode.com/problems/gas-station/description/题意分析:有N个气站围成了圈,每个气站有gas[i],你有一辆车可以从任一气站出发,从气站i出发到i+1需要消耗气cost[i],问能否从任一气站出发,保证车中途气不用完且能回到起点。可以的话输出起点坐标,否则输出-1.题目思路:显而易见的是如果...原创 2018-05-09 23:22:53 · 551 阅读 · 0 评论 -
55 Jump Game
# 55 Jump Game题目来源:https://leetcode.com/problems/jump-game/description/题意分析:给定一个正整数列表,每个数字num表示可以从数字的位置往后num步,开始在第一个数字,问能否到达最后一个数字。栗子: 题目思路:开始我用了暴力枚举法。列表的每个Index都有一个state,检验能够到达该位置,可以的话设为True,否则False,...原创 2018-05-09 23:22:00 · 243 阅读 · 0 评论 -
120 Triangle
# 120 Triangle题目来源:https://leetcode.com/problems/triangle/description/题意分析:给定一个三角形,找到一条使经过数值之和最小的从顶到下的路径,每次只能移动到下一层相邻的结点。题目要求只能使用O(n)的额外空间,n为三角形行数。栗子: 题目思路:经典的动态规划问题,先不管空间问题,创建一个类似的三角形res_triangle,每个位...原创 2018-05-09 23:21:11 · 352 阅读 · 0 评论 -
213 House Robber
# 213 House Robber题目来源:https://leetcode.com/problems/house-robber-ii/description/题意分析:给定一个正整数列表,列表头尾相连成环,要求不能取相邻的正整数,输出能取出的数的和。题目思路:首先假设该列表不成环,那么就是经典的动态规划问题,设前i+1个正整数取到的最大和为sum[i],容易知道sum[0]=nums[0],s...原创 2018-05-09 23:19:20 · 188 阅读 · 0 评论