2013年11月20日
摘要:
1 public class Solution { 2 public boolean isNumber(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 false; 7 char[] sArr = s.trim().toCharArray... 阅读全文
摘要:
1 public class Solution { 2 public String minWindow(String S, String T) { 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 || T == null || S.length() == 0 || T.length() == 0) ... 阅读全文
摘要:
1 public class Solution { 2 public boolean isMatch(String s, String p) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int sLen = s.length(), pLen = p.length(); 6 int i = 0, j = ... 阅读全文
摘要:
1 public class Solution { 2 public boolean isInterleave(String s1, String s2, String s3) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int len1 = s1.length(), len2 = s2.length(), len3 =... 阅读全文
摘要:
1 /** 2 * Definition for binary tree 3 * public class TreeNode { 4 * int val; 5 * TreeNode left; 6 * TreeNode right; 7 * TreeNode(int x) { val = x; } 8 * } 9 */10 public class Solution {11 public int maxPathSum(TreeNode root) {12 ArrayList maxSum = new ArrayList(... 阅读全文
摘要:
1 public class Solution { 2 public boolean isMatch(String s, String p) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 if(p == null||p.length() == 0) return s == null||s.length()==0; 6 ... 阅读全文
摘要:
1 public class Solution { 2 public ArrayList merge(ArrayList intervals) { 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 if(intervals == null... 阅读全文
摘要:
1 public class Solution { 2 public boolean isScramble(String s1, String s2) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int n=s1.length(); 6 boolean[][][] dp=new boolean[n][n... 阅读全文
摘要:
1 public class Solution { 2 public ArrayList spiralOrder(int[][] matrix) { 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 if(matrix == null||... 阅读全文
摘要:
1 public class Solution { 2 public void solveSudoku(char[][] board) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 solveSudokuRecursive(board); 6 } 7 private boolean solveSudoku... 阅读全文
摘要:
1 public class Solution { 2 public static ArrayList restoreIpAddresses(String s) { 3 // Start typing your Java solution below 4 // DO NOT write main() function 5 ArrayList result = new ArrayList(); 6 if (s == null || s.length() == 0) { 7 return result... 阅读全文
摘要:
1 public class Solution { 2 public String strStr(String haystack, String needle) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 int needleLen = needle.length(); 6 int haystackLe... 阅读全文
摘要:
1 public class Solution { 2 public ArrayList insert(ArrayList intervals, Interval newInterval) { 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 ... 阅读全文
摘要:
threaded binary tree 1 public class Solution { 2 public void recoverTree(TreeNode root) { 3 // IMPORTANT: Please reset any member data you declared, as 4 // the same Solution instance will be reused for each test case. 5 TreeNode f1 = null, f2 = null; 6 TreeNode ... 阅读全文
摘要:
1 public class Solution { 2 public int firstMissingPositive(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 int len = A.length; 6 for (int i = 0; i 0 && A[i] != i + 1 &... 阅读全文
摘要:
1 public class Solution { 2 public ListNode rotateRight(ListNode head, 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(head == null || n == 0){ 6 return head; 7 ... 阅读全文
摘要:
1 public class Solution { 2 public String longestPalindrome(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 n = s.length(); 6 if (n == 0) return ""; 7 Strin... 阅读全文
摘要:
similar with 3Sum. O(n3) 1 public class Solution { 2 public ArrayList> fourSum(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 Arrays.sort(num); 6 HashSet> ... 阅读全文
|