摘要: Graph, DFS (1) Build the map, the key is dividend, the value is also a map whose key is divisor and value is its parameter. For example, a / b = 2.0, 阅读全文
posted @ 2017-07-13 18:49 apanda009 阅读(118) 评论(0) 推荐(0) 编辑
摘要: 这道题给我们一个二维数组,让我们求矩阵中最长的递增路径,规定我们只能上下左右行走,不能走斜线或者是超过了边界。那么这道题的解法要用递归和DP来解,用DP的原因是为了提高效率,避免重复运算。我们需要维护一个二维动态数组dp,其中dp[i][j]表示数组中以(i,j)为起点的最长递增路径的长度,初始将d 阅读全文
posted @ 2017-07-13 11:00 apanda009 阅读(127) 评论(0) 推荐(0) 编辑
摘要: carry sum 处理字符串的运算问题, 在转化成数值: (int) (num1.charAt(i) - '0') 转换成数值(同 Character.getNumericValue(char a) ), 非ASCII 码. 再 转化成字符. 也常转化成AScII 码, 在转换成字符串, 所以看看 阅读全文
posted @ 2017-07-13 10:21 apanda009 阅读(134) 评论(0) 推荐(0) 编辑
摘要: Example: 矩阵涉及到计算的问题常常根据题意, 目的找规律 阅读全文
posted @ 2017-07-11 21:26 apanda009 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 这道题还是蛮有创意的一道题,是说自然数序列看成一个长字符串,问我们第N位上的数字是什么。那么这道题的关键就是要找出第N位所在的数字,然后可以把数字转为字符串,这样直接可以访问任何一位。那么我们首先来分析自然数序列和其位数的关系,前九个数都是1位的,然后10到99总共90个数字都是两位的,100到99 阅读全文
posted @ 2017-07-11 18:57 apanda009 阅读(165) 评论(0) 推荐(0) 编辑
摘要: A binary watch has 4 LEDs on the top which represent the hours (0-11), and the 6 LEDs on the bottom represent the minutes (0-59). Each LED represents 阅读全文
posted @ 2017-07-11 17:18 apanda009 阅读(144) 评论(0) 推荐(0) 编辑
摘要: Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover of a rectangular region. Each rectangle is represented 阅读全文
posted @ 2017-07-11 13:10 apanda009 阅读(127) 评论(0) 推荐(0) 编辑
摘要: refer to: https://discuss.leetcode.com/topic/60394/easy-concept-with-python-c-java-solution E.g.input: [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]subar 阅读全文
posted @ 2017-07-10 23:05 apanda009 阅读(228) 评论(0) 推荐(0) 编辑
摘要: 编解码法 复杂度 时间 O(NN) 空间 O(1) 思路 最简单的方法是再建一个矩阵保存,不过当inplace解时,如果我们直接根据每个点周围的存活数量来修改当前值,由于矩阵是顺序遍历的,这样会影响到下一个点的计算。如何在修改值的同时又保证下一个点的计算不会被影响呢?实际上我们只要将值稍作编码就行了 阅读全文
posted @ 2017-07-10 18:01 apanda009 阅读(144) 评论(0) 推荐(0) 编辑
摘要: 我的做法, hashMap, O(n) space, O(n) time: 用ascii 码表, 时间, 空间都是O(1) 学会转化: (int) s.charAt(i) 阅读全文
posted @ 2017-07-09 21:37 apanda009 阅读(133) 评论(0) 推荐(0) 编辑