
LeetCode
Alden He
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
合并两个排序的链表
输入两个单调递增的链表,输出两个链表合成后的链表,当然我们需要合成后的链表满足单调不减规则。使用递归实现,注意边界条件public ListNode Merge(ListNode list1,ListNode list2) { if(list1==null)return list2; if(list2==null)return list1; ...原创 2019-04-17 19:48:30 · 106 阅读 · 0 评论 -
416. Partition Equal Subset Sum
Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.Note:Each of the array elemen...原创 2019-05-30 10:52:47 · 121 阅读 · 0 评论 -
221. Maximal Square
Given a 2D binary matrix filled with 0’s and 1’s, find the largest square containing only 1’s and return its area.Example:Input: 1 0 1 0 01 0 1 1 11 1 1 1 11 0 0 1 0Output: 4思路:动态规划如果(i,j)...原创 2019-05-13 09:54:36 · 194 阅读 · 0 评论 -
823. Binary Trees With Factors
Given an array of unique integers, each integer is strictly greater than 1.We make a binary tree using these integers and each number may be used for any number of times.Each non-leaf node’s value s...原创 2019-05-13 09:30:58 · 130 阅读 · 0 评论 -
878. Nth Magical Number
A positive integer is magical if it is divisible by either A or B.Return the N-th magical number. Since the answer may be very large, return it modulo 10^9 + 7.Example 1:Input: N = 1, A = 2, B = 3...原创 2019-05-10 10:15:59 · 175 阅读 · 0 评论 -
391. Perfect Rectangle
Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover of a rectangular region.Each rectangle is represented as a bottom-left point and a top-right point. ...原创 2019-05-09 14:51:16 · 156 阅读 · 0 评论 -
154. Find Minimum in Rotated Sorted Array II
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).Find the minimum element.The array may contain d...原创 2019-05-14 11:07:20 · 123 阅读 · 0 评论 -
Search in Rotated Sorted Array
Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found in...原创 2019-05-14 10:39:56 · 115 阅读 · 0 评论 -
82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.Example 1:Input: 1->2->3->3->4->4->5Output: 1->2...原创 2019-04-30 22:31:49 · 165 阅读 · 0 评论 -
删除链表中的重复的节点
题目描述在一个排序的链表中,存在重复的结点,请删除该链表中重复的结点,重复的结点不保留,返回链表头指针。 例如,链表1->2->3->3->4->4->5 处理后为 1->2->5思路:首节点是可以删除的,因此需要定义一个新的头节点,之后就是判断当前节点是否重复,如果重复则跳过,我感觉需要注意的点是最后一个节点的next需要置为null/*...原创 2019-05-03 11:02:54 · 172 阅读 · 0 评论 -
把字符串转换为整数
题目描述将一个字符串转换成一个整数(实现Integer.valueOf(string)的功能,但是string不符合数字要求时返回0),要求不能使用字符串转换整数的库函数。 数值为0或者字符串不是一个合法的数值则返回0。值得一提的点是2019年春招360的编程题就是这题,但是我调试了很久也只能通过89%,结束以后看牛油的讨论发现是只要把返回值改为long就能够通过,我是把int resul...原创 2019-05-03 10:33:46 · 145 阅读 · 0 评论 -
二叉搜索树的后序遍历序列
题目描述输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则输出Yes,否则输出No。假设输入的数组的任意两个数字都互不相同。思路:后序遍历序列最后一个数字可以将前面的序列分为两个部分,第一个部分是全部小于该值,第二个部分是全部大于该值,然后针对这两个子序列进行递归即可public class Solution { public boolean VerifyS...原创 2019-05-03 09:56:46 · 298 阅读 · 0 评论 -
二叉树中和为某一值的路径
题目描述输入一颗二叉树的跟节点和一个整数,打印出二叉树中结点值的和为输入整数的所有路径。路径定义为从树的根结点开始往下一直到叶结点所经过的结点形成一条路径。(注意: 在返回值的list中,数组长度大的数组靠前)思路:通过一个List保存当前前序遍历到的路径,然后判断当前节点是否是叶子节点,如果是叶子节点判断是否等于目标值,如果等于目标值,将当前序列加入目标public class Sol...原创 2019-05-02 22:21:18 · 126 阅读 · 0 评论 -
从上往下打印出二叉树
题目描述从上往下打印出二叉树的每个节点,同层节点从左至右打印。将根节点入队列依次出队列,判断当前节点是否有子节点,有就将子节点入队直到队列为空public ArrayList<Integer> PrintFromTopToBottom(TreeNode root) { Queue<TreeNode> queue=new LinkedList...原创 2019-04-18 08:56:11 · 127 阅读 · 0 评论 -
二叉树的镜像
操作给定的二叉树,将其变换为源二叉树的镜像。输入描述:二叉树的镜像定义:源二叉树8/ 6 10/ \ / 5 7 9 11镜像二叉树8/ 10 6/ \ / 11 9 7 5每次更换左右子树的位置,然后依次递归就好了 public void Mirror(TreeNode root) { if(root==null)ret...原创 2019-04-17 20:15:01 · 111 阅读 · 0 评论 -
判断一棵树是不是另一棵树的子结构
输入两棵二叉树A,B,判断B是不是A的子结构。(ps:我们约定空树不是任意一个树的子结构)主要是要注意边界条件,也就是任意一个树为null,都是要返回false的,然后前序遍历A树,判断每个前序节点是否与B树构成相同即可public boolean HasSubtree(TreeNode root1,TreeNode root2) { if(root1==null||roo...原创 2019-04-17 20:05:04 · 405 阅读 · 0 评论 -
300. Longest Increasing Subsequence
Given an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4 Explanation: The longest increasing subsequence is [2,3,7,101],...原创 2019-08-25 21:08:54 · 149 阅读 · 0 评论