摘要:
Given a number represented as an array of digits, plus one to the number.public class Solution { public int[] plusOne(int[] digits) { int carry = 0; int length = digits.length; digits[length-1] = digits[length -1] + 1; for(int i = length -1 ; i>=0; i--){ ... 阅读全文
摘要:
Given two words (startandend), and a dictionary, find the length of shortest transformation sequence fromstarttoend, such that:Only one letter can be ... 阅读全文
摘要:
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... 阅读全文
摘要:
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possibl... 阅读全文
摘要:
public class Solution { public boolean isPalindrome(String s) { if(s == null || s.length() <2 ){ return true; } String mystring = s.replaceAll("[^A-Za-z0-9]", ""); mystring = mystring.toLowerCase(); // 只需遍历前一半就可以了 for(int i = 0... 阅读全文
摘要:
[解题思路]典型的递归。一步步构造字符串。当左括号出现次数 generateParenthesis(int n) { ArrayList result = new ArrayList(); StringBuilder builder = new StringBuilder(); generate(result, builder, n, n); return result; } public void generate(ArrayList result, StringBuilder builder, int start,... 阅读全文
摘要:
123 * 45 615 + 492 = 5535public class Solution { public String multiply(String num1, String num2) { int l1 = num1.l... 阅读全文
摘要:
有三种情况要考虑:1. 如果两个substring相等的话,则为true2. 如果两个substring中间某一个点,左边的substrings为scramble string,同时右边的substrings也为scramble string,则为true3. 如果两个substring中间某一个点,s1左边的substring和s2右边的substring为scramblestring, 同时s1右边substring和s2左边的substring也为scramblestring,则为truepublic class Solution { public boolean isScramb... 阅读全文