leetcode刷题
文章平均质量分 51
GorMing
这个作者很懒,什么都没留下…
展开
-
101. Symmetric Tree
对于给定的二叉树判断是不是对称的一般有两种方法:递归判断和非递归判断,递归判断的话比较直接,非递归判断能帮助我们更好的理解整一个对称二叉树 Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For example, this binary tree [原创 2017-09-30 15:25:01 · 176 阅读 · 0 评论 -
515. Find Largest Value in Each Tree Row
You need to find the largest value in each row of a binary tree. Example: Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]这道题目也是二叉树的层序遍历的题目,时间复杂度的话是 O(V + E)/** * Defini原创 2017-10-11 22:11:25 · 194 阅读 · 0 评论 -
513. Find Bottom Left Tree Value
Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 3 Output: 1 Example 2: Input: 1 / \原创 2017-10-11 22:15:12 · 129 阅读 · 0 评论 -
70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a posit原创 2017-10-28 17:47:59 · 116 阅读 · 0 评论 -
62. Unique Paths
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below). The robot can only move either down or right at any point in time. The robot is trying to reach the b原创 2017-10-28 17:55:08 · 131 阅读 · 0 评论 -
63. Unique Paths II
Follow up for “Unique Paths”: Now consider if some obstacles are added to the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the gri原创 2017-10-28 17:58:14 · 143 阅读 · 0 评论 -
64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path. Note: You can only move either down or right at原创 2017-10-28 18:01:07 · 131 阅读 · 0 评论 -
95. Unique Binary Search Trees II
Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1…n. For example, Given n = 3, your program should return all 5 unique BST’s shown below. sequen原创 2017-10-29 23:09:15 · 172 阅读 · 0 评论 -
96. Unique Binary Search Trees
Given n, how many structurally unique BST’s (binary search trees) that store values 1…n? For example, Given n = 3, there are a total of 5 unique BST’s. 1 3 3 2 1原创 2017-10-28 18:10:54 · 111 阅读 · 0 评论 -
120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. For example, given the following triangle sequence [ [2],原创 2017-10-31 10:08:47 · 209 阅读 · 0 评论 -
leetcode刷题
94. Binary Tree Inorder Traversal Given a binary tree, return the inorder traversal of its nodes’ values. Example: Input: [1,null,2,3] 1 2 / 3 Output: [1,3,2] /** * Definition for a binary tree node...原创 2018-12-06 01:19:46 · 87 阅读 · 0 评论 -
leetcode 106
106. Construct Binary Tree from Inorder and Postorder Traversal Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume that duplicates do not exist in the tre...原创 2018-12-06 02:51:57 · 476 阅读 · 0 评论 -
690. Employee Importance
You are given a data structure of employee information, which includes the employee’s unique id, his importance value and his direct subordinates’ id. For example, employee 1 is the leader of employ原创 2017-10-11 22:08:40 · 239 阅读 · 0 评论 -
215. Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element. For example Given [3,2,1,5,6,4] and k = 2, return 5.原创 2017-10-11 22:04:45 · 170 阅读 · 0 评论 -
240 Search a 2D Matrix II
遍历二位数组以下是题目: Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties: Integers in each row are sorted in ascending from left to right.原创 2017-10-11 22:00:04 · 165 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
二叉树的层序遍历接借助了两个队列来实现相应的功能,首先判断根节点是否为空,如果根节点为空的话直接返回,不为空,则首先将根节点放入第一个队列里面,然后访问第一个队列里面的元素,将所有第一个队列里面的节点的子节点放入第二个队列,然后将元素从第一个队列弹出直至空,之后再访问第二个队列里的元素,同样的将第二个队列元素的子节点放入第一个队列,弹出直至为空,这样一直循环直到二叉树的末尾。 以下是程序class原创 2017-09-29 14:43:34 · 192 阅读 · 0 评论 -
111. Minimum & Maximum Depth of Binary Tree
Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. 求解二叉树的最小深度的问题比较好的方法就是递归了,递归的时候使用广度优先搜索原创 2017-09-29 13:53:42 · 200 阅读 · 0 评论 -
广度优先搜索
这是一篇介绍广度优先搜索的文章,网上有很多关于广度优先搜索的例子,这篇博客就当做是学习笔记吧! 图在计算机内的表示方法主要有邻接表和邻接矩阵两种。 邻接表:适合在稀疏图,且图的节点比较多的时候,邻接表在判断图的出度的时候比较方便,但是在判断入度的时候就需要遍历整个邻接链表来找到。邻接表存储图的空间复杂度为O(V + E)(V表示节点的个数,E则表示所有的边) 邻接矩阵:适合在稠密的节点比较少的图原创 2017-09-29 11:10:39 · 241 阅读 · 0 评论 -
4. Median of Two Sorted Arrays
题目如下所示: There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)). Example 1:原创 2017-09-27 22:05:35 · 145 阅读 · 0 评论 -
315. Count of Smaller Numbers After Self
首先来看看题目 You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i].原创 2017-09-27 22:00:18 · 176 阅读 · 0 评论 -
23 Merge k Sorted Lists
归并多组有序的链表刚刚在LeetCode上刷了一道题目,显示是hard级别的,但是自己居然编译痛过之后一遍就AC了,想想挺开心的,就写篇博客分析一下这道题目,并且分析这道题目的时间复杂度等 先看题目: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity原创 2017-09-26 11:23:05 · 224 阅读 · 0 评论 -
169 Majority Element & 53 Maximum Subarray
摩尔定律与寻找最大子数组 Moore’s Voting Algorithm Find the Largest Subarray Moore’s Voting Algorithm关于摩尔的投票算法可以点击链接在维基百科上面看到详细的解释与说明,使用Moore的投票定律,可以很方便的在O(n)的时间复杂度,O(1)的空间复杂度里面选择出一组数据里面出现次数最多的数据。 以下是题目1: Give原创 2017-09-25 09:21:32 · 207 阅读 · 0 评论 -
借助链表实现两个数的相加
链式列表的数字高位在前与低位在前这篇博客主要讲了借助链表实现两个数字的相加。链表分别是高位数字在前和低位数字在前 高位在前 低位在前 高位在前 You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and eac原创 2017-09-17 18:20:29 · 416 阅读 · 0 评论 -
插入排序与归并排序
浅谈插入排序与归并排序关于排序似乎从大一开始学习变成就开始在使用各种排序方法了,今天看了下有关于插入排序和归并排序的内容,并且对应在 LeetCode 上面做了两道测试题,因此就对插入排序和归并排序做一个简单的小结吧,就当做是我的学习笔记,大佬请勿嘲笑! 插入排序 归并排序 插入排序 关于插入排序主要的思想就是从左到右的遍历一个序列,有一个标识来标记,保证左边的序列有序,再往右遍历的过程中将序列原创 2017-09-09 21:49:08 · 1100 阅读 · 0 评论 -
199. Binary Tree Right Side View
Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given the following binary tree,原创 2017-10-02 10:20:00 · 130 阅读 · 0 评论 -
Add to List 542. 01 Matrix
Given a matrix consists of 0 and 1, find the distance of the nearest 0 for each cell. The distance between two adjacent cells is 1. Example 1: Input: 0 0 0 0 1 0 0 0 0 Output:原创 2017-10-11 21:52:34 · 270 阅读 · 0 评论 -
241 Different Ways to Add Parentheses
这一篇博客主要使用了递归的方式来实现具体的问题主要讲的是LeetCode上面的三道题目 Different Ways to Add Parentheses Kth Largest Element in an Array Search a 2D Matrix II 添加括号的不同方式先来看看题目要求: Given a string of numbers and operators, return原创 2017-09-25 16:47:20 · 192 阅读 · 0 评论 -
110. Balanced Binary Tree
110. Balanced Binary Tree Given a binary tree, determine if it is height-balanced. For this problem, a height-balanced binary tree is defined as: a binary tree in which the depth of the two subtrees o...原创 2018-12-17 23:02:25 · 103 阅读 · 0 评论