
leetcode
亚特兰蒂斯 ‘
已脱离码代码苦海,去体制内了
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
(python) 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. 解析: 找二叉树的根节点离最近叶节点的深度 1,判断当前结点的左右子树是否...原创 2019-05-13 17:42:54 · 130 阅读 · 0 评论 -
(python) 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”, ""] ...原创 2019-05-13 17:49:50 · 273 阅读 · 0 评论 -
(python) 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. 解析: 寻找平面内最多的共线点个数 方法就是穷举法,通过计算共起点的斜率相等来判断共线情况 斜率计算:(y2-y1)/(x2-x1) 注意这里软件计算斜率会有精度问题,所以采用真分数的形式来表...原创 2019-05-13 20:04:02 · 281 阅读 · 0 评论 -
(python) leetcode刷题——sort-list
题目: Sort a linked list in O(n log n) time using constant space complexity. 解析: 对单链表进行时间复杂度为O(nlogn),空间复杂度为O(1)的排序算法 单链表的归并排序时间复杂度为O(nlogn),由于结构特殊性,只需要一个辅助的节点,空间复杂度恒定。 下面作图演示算法过程: 1,输入:【3,4,2,1】 2,递归找...原创 2019-05-14 15:50:54 · 304 阅读 · 0 评论 -
(python) leetcode刷题——insertion-sort-list
题目: Sort a linked list using insertion sort. 解析: 对单链表进行插入排序,那插入排序的思想是将a[i]与a[0]到a[i-1]中比它大的所有元素依次交换,在单链表结构中,只需找到a[0]到a[i-1]中第一个比a[i]大的元素,进行链接重排即可。 具体步骤如下图: 代码: def insertion_sort(start): l = sta...原创 2019-05-27 10:55:45 · 198 阅读 · 0 评论 -
(python) leetcode刷题——binary-tree-postorder-traversal
题目: Given a binary tree, return the postorder traversal of it’s nodes’ values. For example: Given binary tree{1,#,2,3}, 1 2 / 3 return[3,2,1]. Note: Recursive solution is trivial, could you do it ite...原创 2019-06-01 11:07:39 · 222 阅读 · 0 评论