随笔分类 -  Math

摘要:private static String convertBinary(int sum) { StringBuffer binary = new StringBuffer(); while (true) { binary.insert(0, sum % 2); sum = sum / 2... 阅读全文
posted @ 2017-12-03 08:53 apanda009 阅读(177) 评论(0) 推荐(0)
摘要:Here is a way you can do it by hand. Basically the idea is we take in some numbers we don't want to generate, then we generate a random number and if 阅读全文
posted @ 2017-12-02 08:07 apanda009 阅读(310) 评论(0) 推荐(0)
摘要:Brute Force的做法,N个点两两可以构成N(N-1)/2条线,我们可以找这N(N-1)/2条线中线上点数最大值,只需对每一条线再进行一层O(N)的遍历,总共是O(N^3)。 用第二种方法更好,选一个基准点, 看后面每一个点跟它构成的直线, 维护一个HashMap, key是跟这个点构成直线的 阅读全文
posted @ 2017-11-30 22:08 apanda009 阅读(231) 评论(0) 推荐(0)
摘要:We only need to consider special cases which n<=2 and m < 3. When n >2 and m >=3, the result is 8.The four buttons: If we use button 1 and 2, it equal 阅读全文
posted @ 2017-11-30 01:25 apanda009 阅读(192) 评论(0) 推荐(0)
摘要:Solution 1: Reservior sampling: (wiki introduction) Reservoir sampling is a family of randomized algorithms for randomly choosing a sample of k items 阅读全文
posted @ 2017-11-28 01:36 apanda009 阅读(175) 评论(0) 推荐(0)
摘要:Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in logarithmic time complexity. Credits:Special thanks t 阅读全文
posted @ 2017-10-22 05:32 apanda009 阅读(100) 评论(0) 推荐(0)
摘要:Given an integer array ‘arr[]’ of size n, find sum of all sub-arrays of given array. Examples: If we take a close look then we observe a pattern. Let 阅读全文
posted @ 2017-10-20 21:42 apanda009 阅读(317) 评论(0) 推荐(0)
摘要:This solution is just a java version derived from this post. At first, lets look at the edge cases - Now the main algorithm works in following steps - 阅读全文
posted @ 2017-10-16 02:17 apanda009 阅读(152) 评论(0) 推荐(0)
摘要:Given an array containing n distinct numbers taken from 0, 1, 2, ..., n, find the one that is missing from the array. For example, Given nums = [0, 1, 3] return 2. Note: Your algorithm should run i... 阅读全文
posted @ 2017-10-10 01:15 apanda009 阅读(133) 评论(0) 推荐(0)
摘要:Leetcode 12, 13(需要考虑输入不合法的情况,比如“VV”或者“IIII”都是不合法的输入,要输出错误信息): if (s.indexOf(II) .. throw new A.... 如今我们最常见的罗马数字就是钟表的表盘符号:Ⅰ,Ⅱ,Ⅲ,Ⅳ(IIII),Ⅴ,Ⅵ,Ⅶ,Ⅷ,Ⅸ,Ⅹ,Ⅺ,Ⅻ 阅读全文
posted @ 2017-08-18 22:10 apanda009 阅读(169) 评论(0) 推荐(0)
摘要:这道题让我们判断一个数是否为2的次方数,而且要求时间和空间复杂度都为常数,那么对于这种玩数字的题,我们应该首先考虑位操作 Bit Operation。在LeetCode中,位操作的题有很多,比如比如Repeated DNA Sequences 求重复的DNA序列, Single Number 单独的 阅读全文
posted @ 2017-07-15 11:08 apanda009 阅读(163) 评论(0) 推荐(0)
摘要:Map.Entry<> entry : map.entrySet() 阅读全文
posted @ 2017-07-15 10:55 apanda009 阅读(122) 评论(0) 推荐(0)
摘要:存在正负情况,处理方式是按正数处理,符号最后在判断,那么我们需要把除数和被除数取绝对值,那么问题就来了:由于整型数INT的取值范围是-2147483648~2147483647,而对-2147483648取绝对值就会超出范围,所以我们需要先转为long long型再取绝对值。那么怎么样找循环呢,肯定 阅读全文
posted @ 2017-07-14 13:54 apanda009 阅读(158) 评论(0) 推荐(0)
摘要:carry sum 处理字符串的运算问题, 在转化成数值: (int) (num1.charAt(i) - '0') 转换成数值(同 Character.getNumericValue(char a) ), 非ASCII 码. 再 转化成字符. 也常转化成AScII 码, 在转换成字符串, 所以看看 阅读全文
posted @ 2017-07-13 10:21 apanda009 阅读(141) 评论(0) 推荐(0)
摘要:Example: 矩阵涉及到计算的问题常常根据题意, 目的找规律 阅读全文
posted @ 2017-07-11 21:26 apanda009 阅读(148) 评论(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 阅读(143) 评论(0) 推荐(0)
摘要:https://leetcode.com/problems/valid-perfect-square/#/solutions 数学问题常考虑是否越界, 用long? 阅读全文
posted @ 2017-06-29 10:25 apanda009 阅读(140) 评论(0) 推荐(0)
摘要:https://leetcode.com/submissions/detail/106777290/ http://www.cnblogs.com/EdwardLiu/p/3981176.html Linkedin: 直接比较就行, 不用compare 或用newton,比较短: 计算x2 = n的 阅读全文
posted @ 2017-06-21 12:42 apanda009 阅读(225) 评论(0) 推荐(0)