Math
liujunlovecs
这个作者很懒,什么都没留下…
展开
-
Leetcode#13||Roman to Integer
public class Solution { public int romanToInt(String s) { if (s == null || s.length() == 0) { return 0; } Map map = new HashMap(); map.put('I',原创 2015-08-11 16:52:20 · 220 阅读 · 0 评论 -
Leetcode#69||Sqrt(x)
public class Solution { public int mySqrt(int x) { if (x < 0) { return -1; } int left = 1; int right = x; while (left <= right原创 2015-08-18 15:36:59 · 258 阅读 · 0 评论 -
Leetcode#60||Permutation Sequence
public class Solution { public String getPermutation(int n, int k) { StringBuilder result = new StringBuilder(); List list = new ArrayList(); int factorial = 1;原创 2015-08-18 10:59:01 · 331 阅读 · 0 评论 -
Leetcode#67||Add Binary
public class Solution { public String addBinary(String a, String b) { if (a.length() < b.length()) { String temp = a; a = b; b = temp; }原创 2015-08-18 15:20:34 · 273 阅读 · 0 评论 -
Leetcode#65||Valid Number
public class Solution { public boolean isNumber(String s) { int length = s.length(); int i = 0; int e = length - 1; while (i < length && Character原创 2015-08-18 14:47:35 · 376 阅读 · 0 评论 -
Leetcode#50||Pow (x, n)
public class Solution { public double myPow(double x, int n) { if (n < 0) { return 1 / pow(x, -n); } else { return pow(x, n); } }原创 2015-08-17 10:13:52 · 277 阅读 · 0 评论 -
Leetcode#43||Multiply Strings
public class Solution { public String multiply(String num1, String num2) { String s1 = new StringBuilder(num1).reverse().toString(); String s2 = new StringBuilder(num2).reverse().t原创 2015-08-15 17:02:31 · 252 阅读 · 0 评论 -
Leetcode#29||Divide Two Integers
public class Solution { public int divide(int dividend, int divisor) { if (divisor == 0) { return Integer.MAX_VALUE; } if (divisor == -1 && dividend == Integer.原创 2015-08-13 08:28:09 · 240 阅读 · 0 评论 -
Leetcode#9||Palindrome Number
public class Solution { public boolean isPalindrome(int x) { if (x < 0) { return false; } int divisor = 1; while (x / divisor >= 10) {原创 2015-08-11 14:51:14 · 218 阅读 · 0 评论 -
Leetcode#12||Integer to Roman
public class Solution { public String intToRoman(int num) { if (num < 0) { return ""; } int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5,原创 2015-08-11 16:42:58 · 224 阅读 · 0 评论 -
Leetcode#7||Reverse Integer
Java中取余数: (结果与被除数同号) 1、 5 % 3 = 2; 2、 -5 % 3 = -2; 3、 5 % -3 = 2; 4、 -5 % -3 = -2; public class Solution { public int reverse(int x) { int reverse = 0;原创 2015-08-11 14:06:39 · 238 阅读 · 0 评论 -
Leetcode#6||Zigzag Conversion
public class Solution { public String convert(String s, int numRows) { if (numRows == 1 || s.length() <= numRows) { return s; } StringBuilder sb = new原创 2015-08-11 12:01:47 · 223 阅读 · 0 评论 -
Leetcode#2||Add Two Numbers
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode addT原创 2015-08-11 09:27:37 · 250 阅读 · 0 评论 -
Leetcode#66||Plus One
public class Solution { public int[] plusOne(int[] digits) { if (digits == null || digits.length == 0) { return digits; } int carry = 1;原创 2015-08-18 14:54:28 · 285 阅读 · 0 评论