
数学
文章平均质量分 63
nicaishibiantai
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
罗马数字转化
罗马转数字,如果i位比i+1位小,那么说明是i+1位的字母代表数字 - i位的数字。例如: XL, X ( = 10) < L ( =50),那么应该为L-X = 40. 如果是这个情况,光标左移动两位。否则移动一位。 数字转字母,根据当前数字%dividor的情况,分为9, 5-8, 4, 1-3几种情况。 public class Solution { public int rom原创 2014-08-11 11:31:05 · 550 阅读 · 0 评论 -
Bitwise AND of Numbers Range
Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4. 核心就是求m 和n的最高位是否在一个位置上。我们把n的所有低位置零,只剩下最高位,然后&m。结果或者是两个的最高位,或者是0. public int rangeBitwiseAnd(int m, i原创 2015-04-26 07:07:42 · 385 阅读 · 0 评论 -
Reservoir sampling
Having an input stream of n, select k elements with equal probability. Algorithm: 1. select k elements into the result first 0....k-1 2. for k....n-1 elements, each time i, generate a random n原创 2015-04-17 11:58:43 · 692 阅读 · 0 评论 -
Lintcode - Count digits
Count the number of k's between 0 and n. k can be 0 - 9. Example if n=12, in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], we have FIVE 1's (1, 10, 11, 12) see: http://www.hawstein.com/post原创 2015-02-01 09:22:12 · 3352 阅读 · 0 评论 -
Sqrt double
EPI: https://code.google.com/p/elements-of-programming-interviews/source/browse/trunk/Square_root.cpp public static double sqrt(double num) { double left = 0, right = 0; if (num <原创 2015-04-07 12:31:33 · 983 阅读 · 0 评论 -
Divide two integers
注意dividend, divisor 为边界的情况。还有j public int divide(int dividend, int divisor) { if (divisor == 0) { return Integer.MAX_VALUE; } int result = 0; if (d原创 2014-09-01 13:43:29 · 397 阅读 · 0 评论 -
Palindrome Number
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of convertin原创 2015-03-23 05:09:41 · 365 阅读 · 0 评论 -
Multiply String
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. public String multiply(String n原创 2014-09-01 12:52:29 · 603 阅读 · 0 评论 -
atoi
public class Solution { public int atoi(String str) { int sign = 1; boolean checkSign = true; boolean checkFirst = true; int result = 0; for (int i原创 2014-08-11 11:32:03 · 331 阅读 · 0 评论 -
Fraction to recurring decimal
Given two integers representing the numerator and denominator of a fraction, return the fraction in string format. If the fractional part is repeating, enclose the repeating part in parentheses.原创 2014-12-30 07:20:07 · 483 阅读 · 0 评论 -
Sqrt(x)
public int sqrt(int x) { if (x < 0) { return -1; } if (x == 0 || x == 1) { return x; } int high = x; int low = 1; while (low <= high) {原创 2014-09-01 06:28:10 · 429 阅读 · 0 评论 -
Lintcode - Hash fucntion
In data structure Hash, hash function is used to convert a string(or any other type) into an integer smaller than hash size and bigger or equal to zero. The objective of designing a hash function is t原创 2015-01-31 14:42:05 · 3266 阅读 · 0 评论 -
pow(x,n)
注意n为负数的情况 public double pow(double x, int n) { int sign = n < 0 ? -1 : 1; n = Math.abs(n); double result = helper(x, n); return sign == 1 ? result : (double) 1/res原创 2014-08-29 13:20:29 · 393 阅读 · 0 评论 -
Add Binary
Given two binary strings, return their sum (also a binary string). For example, a = "11" b = "1" Return "100". 容易错的地方: public String addBinary(String a, String b) { String原创 2014-08-30 13:14:14 · 492 阅读 · 0 评论 -
Single Number II
Given an array of integers, every element appears three times except for one. Find that single one. Note: Your algorithm should have a linear runtime complexity. Could you implement it without u原创 2014-08-28 12:11:19 · 521 阅读 · 0 评论 -
Permutation Sequence
public String getPermutation(int n, int k) { List num = new ArrayList(); for (int i = 0; i < n; i++) { num.add(i+1); } int factorial = 1; for (int i原创 2014-09-21 04:03:22 · 655 阅读 · 0 评论 -
Find prime numbers
public static List findPrime(int n) { List preResult = new ArrayList(); List result = new ArrayList(); for (int i = 1; i <= n; i++) { preResult.add(i); } int divisorInd = 1; // start fro原创 2014-08-25 11:57:42 · 526 阅读 · 0 评论 -
Repeated DNA Sequences
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA. Wri原创 2015-04-28 05:24:07 · 437 阅读 · 0 评论