leetcode
文章平均质量分 66
岸芃
有梦为马,随处可栖
展开
-
Leetcode:minimum-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-05-22 22:17:13 · 320 阅读 · 0 评论 -
Leetcode:evaluate-reverse-polish-notation
题目描述:Evaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are+,-,*,/. Each operand may be an integer or another expression.Some examples: ["2", "1原创 2017-05-22 22:47:24 · 303 阅读 · 0 评论 -
Leetcode: sort-list
题目:Sort a linked list in O(n log n) time using constant space complexity.分析:在排序算法中,时间复杂度为O(n log n)的算法有快速排序,归并排序和堆排序。但由于链表的归并排序时间复杂度为O(1),所以在这里选用归并排序。归并排序的思想是将链表不断的一分为二,然后进行排序,最后将一原创 2017-05-23 12:21:29 · 385 阅读 · 0 评论 -
Leetcode: max-points-on-a-line
题目:Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.分析:题目是给定一个二维平面上的点,希望求得这个平面上经过最多点的直线经过了多少个点。解这个题目需要用到穷举的思想,即计算每个点到其他点的斜率,如果斜率相同,则共线原创 2017-05-23 20:40:04 · 656 阅读 · 1 评论 -
Leetcode: insertion-sort-list
题目:Sort a linked list using insertion sort.分析:题目要求用插入排序对一个链表进行排序,那么思路就是构建一个新的链表,将原链表中符合大小条件的结点插入到新链表中。具体代码的实现如下:/** * Definition for singly-linked list. * public class ListNo原创 2017-05-23 21:32:11 · 304 阅读 · 0 评论 -
Leetcode: reorder-list
题目:Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorde原创 2017-05-24 10:41:59 · 437 阅读 · 0 评论 -
Leetcode: linked-list-cycle-ii
题目:Given a linked list, return the node where the cycle begins. If there is no cycle, return null.Follow up:Can you solve it without using extra space?分析:给定一个链表,返回这个链表中环的开始,若无环,那么返回n原创 2017-05-24 17:41:30 · 480 阅读 · 0 评论 -
Leetcode: binary-tree-zigzag-level-order-traversal
题目:Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:原创 2017-05-26 16:06:03 · 539 阅读 · 0 评论 -
Leetcode: symmetric-tree
题目:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3原创 2017-05-26 16:34:21 · 596 阅读 · 0 评论