随笔分类 -  +-*/

摘要:Given two binary strings, return their sum (also a binary string).For example,a ="11"b ="1"Return"100".StringBuilder + reverse methodpublic class Solution { public String addBinary(String a, String b) { if(a == null || a.equals("")) return b; if(b == null || b 阅读全文
posted @ 2014-01-31 04:02 Razer.Lu 阅读(157) 评论(0) 推荐(0)
摘要:Implementint sqrt(int x).Compute and return the square root ofx.public class Solution { public int sqrt(int x) { int start = 0; int end = x; if(x == 0 || x == 1) return x; while(start x/m){ end = m -1; }else{ s... 阅读全文
posted @ 2014-01-28 16:30 Razer.Lu 阅读(112) 评论(0) 推荐(0)
摘要:public class Solution { public int divide(int dividend, int divisor) { // IMPORTANT: Please reset any member data you declared, as // the same Solution instance will be reused for each test case. if(dividend == 0) return 0; if(divisor == 1) return... 阅读全文
posted @ 2014-01-26 16:48 Razer.Lu 阅读(141) 评论(0) 推荐(0)
摘要:123 * 45 615 + 492 = 5535public class Solution { public String multiply(String num1, String num2) { int l1 = num1.l... 阅读全文
posted @ 2014-01-26 04:08 Razer.Lu 阅读(128) 评论(0) 推荐(0)
摘要:public class Solution { public double pow(double x, int n) { if(n<0){ return 1.0/powHelper(x,n); }else{ return powHelper(x, n); } } public double powHelper(double x, int n){ if(n == 0){ return 1; } double... 阅读全文
posted @ 2014-01-24 12:37 Razer.Lu 阅读(124) 评论(0) 推荐(0)