![](https://img-blog.csdnimg.cn/20201014180756930.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 59
qiqiqi777
这个作者很懒,什么都没留下…
展开
-
Path Sum
//recursive public boolean hasPathSum(TreeNode root, int sum) { // Start typing your Java solution below // DO NOT write main() function if(root == null) return false;原创 2013-08-19 05:27:01 · 371 阅读 · 0 评论 -
Same Tree
public boolean isSameTree(TreeNode p, TreeNode q) { // Start typing your Java solution below // DO NOT write main() function if(p == null && q == null) { return tru原创 2013-08-19 08:01:53 · 311 阅读 · 0 评论 -
Unique Binary Search Trees II
public ArrayList generateTrees(int n) { // Start typing your Java solution below // DO NOT write main() function return generateTrees(1, n); } public ArrayList gen原创 2013-08-21 10:20:21 · 365 阅读 · 0 评论 -
Unique Binary Search Trees
// O(n) time, O(1) space //it is catalan number. Cn = (2n)!/((n+1)!n!) public int numTrees(int n) { // Start typing your Java solution below // DO NOT write main() function原创 2013-08-21 09:35:20 · 375 阅读 · 0 评论 -
Validate Binary Search Tree
public boolean isValidBST(TreeNode root) { // Start typing your Java solution below // DO NOT write main() function return isValidBST(root, Integer.MIN_VALUE, Integer.MAX_VALUE原创 2013-08-21 08:44:51 · 344 阅读 · 0 评论 -
Reverse Linked List II
public ListNode reverseBetween(ListNode head, int m, int n) { // Start typing your Java solution below // DO NOT write main() function if(head == null || m == n) return head;原创 2013-08-21 11:52:40 · 304 阅读 · 0 评论 -
Restore IP Addresses
public ArrayList restoreIpAddresses(String s) { // Start typing your Java solution below // DO NOT write main() function return restoreIpAddresses(s, 1); } public原创 2013-08-21 10:59:20 · 293 阅读 · 0 评论 -
Gray Code
public ArrayList grayCode(int n) { // Start typing your Java solution below // DO NOT write main() function ArrayList result = new ArrayList(); result.add(0); i原创 2013-08-22 04:41:21 · 348 阅读 · 0 评论 -
Merge Sorted Array
public void merge(int A[], int m, int B[], int n) { // Start typing your Java solution below // DO NOT write main() function int end = m + n - 1; while(m > 0 && n > 0)原创 2013-08-22 04:49:45 · 333 阅读 · 0 评论 -
Decode Ways
// one dimension DP public int numDecodings(String s) { // Start typing your Java solution below // DO NOT write main() function if(s == null || s.length() == 0) return 0;原创 2013-08-22 01:56:57 · 332 阅读 · 0 评论 -
Partition List
public ListNode partition(ListNode head, int x) { // Start typing your Java solution below // DO NOT write main() function if(head == null) return null; ListNode tmp =原创 2013-08-22 05:28:12 · 371 阅读 · 0 评论 -
Remove Duplicates from Sorted Array
public int removeDuplicates(int[] A) { // Start typing your Java solution below // DO NOT write main() function if(A.length == 0) return 0; int count = 0; for(i原创 2013-08-22 08:05:08 · 340 阅读 · 0 评论 -
Remove Duplicates from Sorted Array II
public int removeDuplicates(int[] A) { // Start typing your Java solution below // DO NOT write main() function if(A.length == 0) return 0; int count = 0; int t原创 2013-08-22 09:12:32 · 337 阅读 · 0 评论 -
Remove Duplicates from Sorted List
public ListNode deleteDuplicates(ListNode head) { // Start typing your Java solution below // DO NOT write main() function if(head == null) return head; ListNode curren原创 2013-08-22 09:16:25 · 340 阅读 · 0 评论 -
Remove Duplicates from Sorted List II
public ListNode deleteDuplicates(ListNode head) { // Start typing your Java solution below // DO NOT write main() function if(head == null) return head; ListNode dummy原创 2013-08-22 10:05:12 · 355 阅读 · 0 评论 -
Search a 2D Matrix
public boolean searchMatrix(int[][] matrix, int target) { // Start typing your Java solution below // DO NOT write main() function int row = matrix.length; if(row == 0)原创 2013-08-22 11:19:06 · 309 阅读 · 0 评论 -
Sort Colors
//use counting sort, two passes public void sortColors(int[] A) { // Start typing your Java solution below // DO NOT write main() function int[] count = new int[3];原创 2013-08-22 12:16:46 · 360 阅读 · 0 评论 -
Set Matrix Zeroes
public void setZeroes(int[][] matrix) { // Start typing your Java solution below // DO NOT write main() function int m = matrix.length; if(m == 0) return; int n原创 2013-08-22 11:11:01 · 333 阅读 · 0 评论 -
Longest Consecutive Sequence
public int longestConsecutive(int[] num) { // Start typing your Java solution below // DO NOT write main() function if(num.length == 0) return 0; Set set = new HashSet(原创 2013-08-23 10:48:51 · 315 阅读 · 0 评论 -
Merge Two Sorted Lists
public ListNode mergeTwoLists(ListNode l1, ListNode l2) { // Start typing your Java solution below // DO NOT write main() function if(l1 == null) return l2; if(l2 == nu原创 2013-08-24 05:31:29 · 347 阅读 · 0 评论 -
Minimum Path Sum
//two dimensions dp public int minPathSum(int[][] grid) { // Start typing your Java solution below // DO NOT write main() function int m = grid.length; if(m == 0) r原创 2013-08-24 08:38:35 · 354 阅读 · 0 评论 -
Length of Last Word
public int lengthOfLastWord(String s) { // Start typing your Java solution below // DO NOT write main() function if(s == null | s.length() == 0) return 0; int end = s.l原创 2013-08-24 09:18:49 · 347 阅读 · 0 评论 -
First Missing Positive
//bucket sort with constant space public int firstMissingPositive(int[] A) { // Start typing your Java solution below // DO NOT write main() function if(A == null || A.leng原创 2013-08-24 12:22:29 · 358 阅读 · 0 评论 -
Anagrams
public ArrayList anagrams(String[] strs) { // Start typing your Java solution below // DO NOT write main() function ArrayList result = new ArrayList(); if(strs == null原创 2013-08-24 11:45:39 · 358 阅读 · 0 评论 -
Rotate Image
public void rotate(int[][] matrix) { // Start typing your Java solution below // DO NOT write main() function int n = matrix.length; if(n == 0) return; for(int原创 2013-08-24 11:55:08 · 314 阅读 · 0 评论 -
Count and Say
public String countAndSay(int n) { // Start typing your Java solution below // DO NOT write main() function StringBuilder result = new StringBuilder(); if(n == 0) retur原创 2013-08-24 22:24:29 · 443 阅读 · 0 评论 -
Search Insert Position
public int searchInsert(int[] A, int target) { // Start typing your Java solution below // DO NOT write main() function if(A.length == 0) return 0; for(int i = 0; i < A原创 2013-08-24 22:29:13 · 322 阅读 · 0 评论 -
Permutations
//is there some solutions using less space? public ArrayList> permute(int[] num) { // Start typing your Java solution below // DO NOT write main() function ArrayList> resul原创 2013-08-25 09:27:01 · 373 阅读 · 0 评论 -
Add Two Numbers
//recursive public ListNode addTwoNumbers(ListNode l1, ListNode l2) { // Start typing your Java solution below // DO NOT write main() function return addTwoNumbers(l1, l2,原创 2013-08-25 23:21:49 · 391 阅读 · 0 评论 -
3Sum Closest
public int threeSumClosest(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function if(num.length < 3) return Integer.MIN_VALUE;原创 2013-08-26 09:45:35 · 343 阅读 · 0 评论 -
4Sum
public ArrayList> fourSum(int[] num, int target) { // Start typing your Java solution below // DO NOT write main() function ArrayList> result = new ArrayList>(); Set> s原创 2013-08-26 11:14:13 · 386 阅读 · 0 评论 -
Remove Nth Node From End of List
public ListNode removeNthFromEnd(ListNode head, int n) { // Start typing your Java solution below // DO NOT write main() function ListNode fast = head; for(int i = 1; i原创 2013-08-26 11:22:34 · 396 阅读 · 0 评论 -
Permutations II
//space maybe use a lot public ArrayList> permuteUnique(int[] num) { // Start typing your Java solution below // DO NOT write main() function ArrayList> result = new ArrayList>原创 2013-08-25 09:40:45 · 352 阅读 · 0 评论 -
Two Sum
//use hashmap, time: o(n), space: o(n) //if the array if already sorted, we can use two pointers, it will be linear time and space // through we can use two pointers here, it will be o(nlogn原创 2013-08-25 23:06:49 · 397 阅读 · 0 评论 -
3 Sum
public ArrayList> threeSum(int[] num) { // Start typing your Java solution below // DO NOT write main() function Arrays.sort(num); ArrayList> result = new ArrayList>();原创 2013-08-26 09:31:28 · 392 阅读 · 0 评论 -
Search for a Range
public int[] searchRange(int[] A, int target) { // Start typing your Java solution below // DO NOT write main() function return searchRange(A, target, 0, A.length - 1); }原创 2013-08-25 00:02:34 · 340 阅读 · 0 评论 -
Generate Parentheses
public ArrayList generateParenthesis(int n) { // Start typing your Java solution below // DO NOT write main() function ArrayList result = new ArrayList(); char[] c = ne原创 2013-08-25 08:43:03 · 347 阅读 · 0 评论 -
Valid Parentheses
public boolean isValid(String s) { // Start typing your Java solution below // DO NOT write main() function if(s.length() == 0) return true; Stack stack = new Stack();原创 2013-08-25 02:29:46 · 330 阅读 · 0 评论 -
Combinations
//recursive problem, c(n, k) = c(n - 1, k - 1) + c(n - 2, k - 1) + ... + c(k - 1, k - 1); public ArrayList> combine(int n, int k) { // Start typing your Java solution below // DO N原创 2013-08-25 10:30:29 · 429 阅读 · 0 评论 -
Maximum Subarray
//one dimension dp public int maxSubArray(int[] A) { // Start typing your Java solution below // DO NOT write main() function int max = 0; int result = Integer.MIN_原创 2013-08-27 21:55:33 · 296 阅读 · 0 评论