随笔分类 - leetcode- +-*/sqr
摘要:1 public class Solution { 2 public int sqrt(int x) { 3 if(x==0 ||x==1) return x; 4 long start = 1; 5 long end = x-1; 6 while(startx){11 end = mid-1;12 }13 else{14 start = mid+1;15 }16 }17 ...
阅读全文
posted @ 2014-02-06 14:51
krunning
摘要:1 public class Solution { 2 public String addBinary(String a, String b) { 3 int len1 = a.length(); 4 int len2 = b.length(); 5 StringBuilder sb = new StringBuilder(); 6 int p1 = len1-1; 7 int p2 = len2 -1; 8 int carry = 0; 9 while(p1>=0&&p2...
阅读全文
posted @ 2014-02-06 14:32
krunning
摘要:1 public class Solution { 2 public double pow(double x, int n) { 3 if(x==0||x==1) return x; 4 if(n<0)return 1/helper(x,-1*n); 5 else return helper(x,n); 6 } 7 public double helper(double x,int n){ 8 if(n==0) return 1; 9 double res = helper(x,n/2);...
阅读全文
posted @ 2014-02-06 14:18
krunning
摘要:Given two numbers represented as strings, return multiplication of the numbers as a string. 1 public class Solution { 2 public String multiply(String num1, String num2) { 3 if(num1.equals("0")||num2.equals("0")) return "0"; 4 int len1 = num1.length(); 5 int len2 = num2.
阅读全文
posted @ 2014-02-06 14:17
krunning
摘要:Divide two integers without using multiplication, division and mod operator. 1 public class Solution { 2 public int divide(int dividend, int divis...
阅读全文
posted @ 2014-02-06 05:41
krunning
浙公网安备 33010602011771号