
leetcode经典编程题
疯子.
一步一个脚印,踏踏实实
展开
-
给定一棵二叉树,找到它的最小深度。最小深度是从根节点到最近叶节点的最短路径上的节点数量
给定一棵二叉树,找到它的最小深度。最小深度是从根节点到最近叶节点的最短路径上的节点数量原创 2017-12-18 21:49:37 · 3640 阅读 · 0 评论 -
LeetCode--word-break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words. For example, givens ="leetcode",dict =["leet", "code...原创 2018-12-05 11:37:07 · 340 阅读 · 0 评论 -
LeetCode--word-break-ii
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens ="catsa...原创 2018-12-05 10:47:58 · 324 阅读 · 0 评论 -
LeetCode--binary-tree-preorder-traversal
Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[1,2,3].Note: Recursive solution is trivi...原创 2018-11-27 18:47:46 · 165 阅读 · 0 评论 -
LeetCode--binary-tree-postorder-traversal
Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree{1,#,2,3}, 1 \ 2 / 3 return[3,2,1].Note: Recursive solution is triv...原创 2018-11-27 18:45:58 · 160 阅读 · 0 评论 -
LeetCode--linked-list-cycle
Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?思路:快慢指针/** * Definition for singly-linked list. * class ListNode { * int val;...原创 2018-11-30 11:44:56 · 259 阅读 · 0 评论 -
LeetCode--linked-list-cycle-ii
Given a linked list, return the node where the cycle begins. If there is no cycle, returnnull.Follow up:Can you solve it without using extra space?思路:快慢指针/** * Definition for singly-linked lis...原创 2018-11-29 21:40:11 · 237 阅读 · 0 评论 -
LeetCode--reorder-list
Given a singly linked list L: L 0→L 1→…→L n-1→L n,reorder it to: L 0→L n →L 1→L n-1→L 2→L n-2→…You must do this in-place without altering the nodes' values.For example,Given{1,2,3,4}, reorder it...原创 2018-11-29 20:31:30 · 185 阅读 · 0 评论 -
LeetCode--insertion-sort-list
Sort a linked list using insertion sort.使用插入排序对链表排序。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * v...原创 2018-11-25 18:19:20 · 190 阅读 · 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.给定二维平面上的n个点,找出位于同一直线上的最大点数。原文:https://segmentfault.com/a/1190000005678407哈希表法复杂度O(N^2) 时间 O...原创 2018-11-24 16:56:37 · 191 阅读 · 0 评论 -
LeetCode--sort-list
Sort a linked list in O(n log n) time using constant space complexity.使用固定的空间复杂度对链表进行排序,时间复杂度为O(n log n)思路:我们看到排序并且时间复杂度要求是O(n log n),那么想到的排序方法是归并排序,只是使用的对象是链表,在归并排序的思想中,我们做的是每次查找中间下标,然后一分为二,递归下去,...原创 2018-11-25 17:14:31 · 141 阅读 · 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", "+", "3", "...原创 2018-11-23 20:13:40 · 174 阅读 · 0 评论 -
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.给定一棵二叉树,找到它的最小深度。最小深度是沿着从根节点到最近叶节点的最短路径的...原创 2018-11-23 18:06:46 · 163 阅读 · 0 评论 -
Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are+,-,*,
在反向波动表示法中评估算术表达式的值。有效的运算符是+, - ,*,/。 每个操作数可能是一个整数或另一个表达式。原创 2017-12-27 18:02:24 · 362 阅读 · 0 评论 -
LeetCode--copy-list-with-random-pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy of the list./** * Definition for singly-link...原创 2018-12-06 15:14:29 · 418 阅读 · 0 评论