摘要:
use stack 1 public class Solution { 2 public String addBinary(String a, String b) { 3 if(a == null||b == null) 4 return ""; 5 if(a.length() == 0) 6 return b; 7 if(b.length() == 0) 8 return a; 9 Stack stack = new Stack();10 ... 阅读全文
摘要:
use stack 1 public class Solution { 2 public String addBinary(String a, String b) { 3 if(a == null||b == null) 4 return ""; 5 if(a.length() == 0) 6 return b; 7 if(b.length() == 0) 8 return a; 9 Stack stack = new Stack();10 ... 阅读全文
摘要:
use stack 1 public class Solution { 2 public int[] plusOne(int[] digits) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(digits == null) 6 return null; 7 Stack myst... 阅读全文
摘要:
recursion programming 1 public class Solution { 2 public int uniquePaths(int m, int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int[][] result = new int[m+1][n+1]; 6 result... 阅读全文
摘要:
1 public class Solution { 2 public int lengthOfLastWord(String s) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(s == null) 6 return 0; 7 char[] mychar = s.trim()... 阅读全文
摘要:
recursion programming 1 public class Solution { 2 public String countAndSay(int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(n == 1) 6 return "1"; 7 char[] my... 阅读全文
摘要:
use three 2-d matrix to store if any column, row or block has more than one specific value. 1 public class Solution { 2 public boolean isValidSudoku(char[][] board) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for ... 阅读全文
摘要:
simple recursion programming problemelse if(target < A[mid]) return binarySearch(A, start, mid, target); else return binarySearch(A, mid+1, end, target); 1 public class Solution { 2 public int searchInsert(int[] A, int target) { 3 // IMPORTANT: Please res... 阅读全文
摘要:
same asRemove Duplicates from Sorted Array 1 public class Solution { 2 public int removeElement(int[] A, int elem) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(A == null||A.length <... 阅读全文
摘要:
use two index to compress array 1 public class Solution { 2 public int removeDuplicates(int[] A) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(A == null||A.length < 1) 6 ... 阅读全文
摘要:
recursion programming 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * val = x; 8 * next = null; 9 * }10 * }11 */12 public class Solution {13 public ListNode swapPairs(List... 阅读全文
摘要:
fastrunner and slowrunner trick.(be care of head node) 1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * val = x; 8 * next = null; 9 * }10 * }11 */12 public class Solution {13 ... 阅读全文
摘要:
recursion problem 1 public class Solution { 2 public ArrayList letterCombinations(String digits) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 ArrayList result = new ArrayList(); 6 ... 阅读全文
摘要:
similar with 3Sum 1 public class Solution { 2 public int threeSumClosest(int[] num, int target) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(num == null || num.length < 3) 6 ... 阅读全文
摘要:
1 public class Solution { 2 public ArrayList generateParenthesis(int n) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 ArrayList result = new ArrayList(); 6 StringBuilder builde... 阅读全文
摘要:
1 /** 2 * Definition for singly-linked list. 3 * public class ListNode { 4 * int val; 5 * ListNode next; 6 * ListNode(int x) { 7 * val = x; 8 * next = null; 9 * }10 * }11 */12 public class Solution {13 public ListNode mergeTwoLists(ListNode l1, ListNode... 阅读全文
摘要:
use stack (be careful of empty stack) 1 public class Solution { 2 public boolean isValid(String s) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(s == null||s.length() == 0) 6 ... 阅读全文
摘要:
be careful of the special cases(null, 0) 1 public class Solution { 2 public String longestCommonPrefix(String[] strs) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(strs == null||strs... 阅读全文
摘要:
当前一位小于后一位的时候才是后一位减去前一位,并且这种位数只有一位 1 public class Solution { 2 public int romanToInt(String s) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int result = 0; 6 if (s == null || s.... 阅读全文
摘要:
use stringbuffer 1 public class Solution { 2 public String intToRoman(int num) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 StringBuffer result = new StringBuffer(); 6 String[]... 阅读全文
摘要:
brute force O(n2)从头尾两头扫面 O(n) 1 public class Solution { 2 public int maxArea(int[] height) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int start = 0; 6 int end = height.length... 阅读全文
|