九章算法
wch6887164
这个作者很懒,什么都没留下…
展开
-
二分法小结
一个基础模板:注解: 1、mid的表达式之所以不写成mid=(start+end)/2;是因为start+end值可能溢出,而mid=start+(end-start)/2绝对没有溢出的可能,这是一种严谨。 2、while里面的条件是(start+1<end)是因为这样子结束的时候start和end大部分是一左一右情况,也可能是重合的情况。二分法模板的四点要素• start+1&...原创 2018-06-22 15:33:17 · 352 阅读 · 0 评论 -
二叉树与分治法
第一题 求二叉树最大深度遍历方法: 分治方法:public class Solution { /** * @param root: The root of binary tree. * @return: An integer */ public int maxDepth(TreeNode root) { if(root==null...原创 2018-07-02 17:29:45 · 1071 阅读 · 0 评论 -
数组与数
问题一、未排序数组找中位数原创 2018-07-16 17:20:55 · 198 阅读 · 0 评论 -
链表
问题一、删除重复的链表public class Solution { /** * @param head: head is the head of the linked list * @return: head of the linked list */ public ListNode deleteDuplicates(ListNode head) {...原创 2018-07-09 20:55:09 · 160 阅读 · 0 评论 -
数据结构
一、栈 问题:largest-rectangle-in-histogram 描述: 思路:构造一个递增栈,一旦push入栈的元素比栈顶元素小的时候,就计算包括栈顶元素的面积最大值。 public class Solution { /** * @param height: A list of integer * @return: The area of la...原创 2018-07-26 10:00:15 · 191 阅读 · 0 评论