![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
Leetcode
文章平均质量分 76
cucumberguagua
这个作者很懒,什么都没留下…
展开
-
Majority Element
五种方法:Hash table-Runtime: O(n), Space: O(n) Maintain a hash table of the counts of each element, then find the most common one.Randomization-Average runtime: O(n), Worst case runtime: Infinity: R原创 2016-03-14 06:44:19 · 274 阅读 · 0 评论 -
8.2 Subsets II
Link: https://oj.leetcode.com/problems/subsets-ii/public class Solution { public ArrayList> subsetsWithDup(int[] num) { //iterative with binary number. Create a hashset here to remove du原创 2014-07-22 13:40:35 · 322 阅读 · 0 评论 -
2.1.14 Valid Sudoku
Link: https://oj.leetcode.com/problems/valid-sudoku/这题见原创 2014-08-18 07:58:30 · 210 阅读 · 0 评论 -
15.5 Minimum Window Substring
Link: https://oj.leetcode.com/problems/minimum-window-substring/iven a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(n).For原创 2014-08-06 08:13:48 · 339 阅读 · 0 评论 -
10.9 Generate Parentheses
Link:My first attempt: the public class Solution { public ArrayList generateParenthesis(int n) { ArrayList result = new ArrayList(); dfs(n, n, "", result); return resul原创 2014-07-29 01:44:52 · 255 阅读 · 0 评论 -
8.3 Permutations
Link: https://oj.leetcode.com/problems/permutations/Approach I: Recurvipublic class Solution { //iterative. why no backtrack? public ArrayList> permute(int[] num) { ArrayList> resu原创 2014-07-24 02:07:14 · 246 阅读 · 0 评论 -
6.2 Merge Two Sorted Lists
原题链接:Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.原创 2014-07-18 02:46:17 · 238 阅读 · 0 评论 -
6.1 Merge Sorted Array
原题链接:我这次写的和戴的代码一样。t原创 2014-07-18 02:33:50 · 236 阅读 · 0 评论 -
2.1.15 Trapping Rain Water
Link: https://oj.leetcode.com/problems/trapping-rain-water/Given n non-negative integers representing an elevation map where the width of each bar is 1, compute how much water it is able to trap a原创 2014-08-18 09:54:23 · 259 阅读 · 0 评论 -
8.5 Combinations
Link:Approach I: Recursive, DFSI Tpublic class Solution { public ArrayList> combine(int n, int k) { ArrayList> result = new ArrayList>(); if(n<=0 || n < k ) return result;原创 2014-07-24 07:53:05 · 415 阅读 · 0 评论 -
8.1 Subsets
Link:Approach I: Recursionpublic class Solution { public ArrayList> subsets(int[] S) { if(S == null) return null; Arrays.sort(S); return helper(S, S.length - 1); }原创 2014-07-22 06:17:19 · 550 阅读 · 0 评论 -
2.1.6 Longest Consecutive Sequence
Link: https://oj.leetcode.com/problems/longest-consecutive-sequence/Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example,Given [100, 4,原创 2014-08-12 07:14:58 · 349 阅读 · 0 评论 -
2.2.9 Reverse Nodes in K-group
Link: https://oj.leetcode.com/problems/reverse-nodes-in-k-group/Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a m原创 2014-08-25 06:50:06 · 322 阅读 · 0 评论 -
2.2.10 Copy List with Random Pointer
这题我第一眼看上去觉得很简单。看了一下戴的提示:两遍扫描。我认为应该是一遍copy node value,原创 2014-07-03 08:04:12 · 326 阅读 · 0 评论 -
2.1.9 3Sum Closest
Link: 这题和3Sum 几乎一样。public class Solution { public int threeSumClosest(int[] num, int target) { Arrays.sort(num); int gap = Integer.MAX_VALUE; int result = Integer.MAX_V原创 2014-08-13 06:18:15 · 301 阅读 · 0 评论 -
2.1.10 4Sum
Link: https://oj.leetcode.com/problems/4sum/Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array whic原创 2014-08-14 07:49:29 · 261 阅读 · 0 评论 -
2.1.11 Remove Element
Link: https://oj.leetcode.com/submissions/detail/9751364/原创 2014-08-14 09:00:09 · 259 阅读 · 0 评论 -
2.1.12 Next Permutation
Link: https://oj.leetcode.com/problems/next-permutation/原创 2014-08-14 14:27:21 · 414 阅读 · 0 评论 -
2.1.13 Permutation Sequence
Link: http://www.lifeincode.net/programming/leetcode-permutation-sequence-java/原创 2014-08-15 09:03:35 · 344 阅读 · 0 评论 -
2.1.17 Plus One
Link: Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of the list.原创 2014-08-18 12:44:34 · 335 阅读 · 0 评论 -
2.1.23 Single Number
Link: https://oj.leetcode.com/problems/single-number/Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runti原创 2014-08-19 08:46:20 · 226 阅读 · 0 评论 -
4.1.4 Evaluate Reverse Polish Notation
这题简单。基本一次过。注意push 进原创 2014-07-10 13:30:00 · 206 阅读 · 0 评论 -
3.3 String to Integer(atoi)
按照leetcode戴的C++版本对照写的java版。还需要再联系单独写。原创 2014-07-07 07:04:01 · 266 阅读 · 0 评论 -
2.1.8 3Sum
Link: https://oj.leetcode.com/problems/3sum/这题和2sumApproach I:原创 2014-08-13 05:43:39 · 599 阅读 · 0 评论 -
3.2 Implement strStr()
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.原创 2014-07-06 05:52:59 · 431 阅读 · 0 评论 -
2.1.7 Two Sum
Link: https://oj.leetcode.com/problems/two-sum/原创 2014-08-12 08:45:33 · 414 阅读 · 0 评论 -
2.1.3 Search in Rotated Sorted Array
Link: My code:public class Solution { public int search(int[] A, int target) { if(A == null || A.length == 0) return -1; return helper(A, target, 0, A.length); } p原创 2014-08-11 09:10:37 · 277 阅读 · 0 评论 -
Kth Largest Element in an Array
123原创 2016-01-27 15:39:15 · 284 阅读 · 0 评论 -
3.9 Valid Number
我没有思路。参考类似有限自动机原创 2014-07-09 02:42:37 · 350 阅读 · 0 评论 -
2.1.4 Search in Rotated Sorted Array II
Link: Follow up for "Search in Rotated Sorted Array":What if duplicates are allowed?Would this affect the run-time complexity? How and why?Write a function to determine if a given target is原创 2014-08-11 12:56:34 · 210 阅读 · 0 评论 -
5.1.2 Binary Tree Inorder Traversal
原题链接:https://oj.leetcode.com/problems/binary-tree-inorder-traversal/原创 2014-07-11 05:46:56 · 256 阅读 · 0 评论 -
8.4 Permutations II
Link: http://blog.csdn.net/linhuanmars/article/details/21570835原创 2014-07-24 04:40:23 · 354 阅读 · 0 评论 -
DFS 总结
1 Subsets 2 Subsets II3 Combinations原创 2014-08-31 11:37:07 · 455 阅读 · 0 评论 -
2.1.16 Rotate Image
Link: You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Follow up:Could you do this in-place?原创 2014-08-18 12:16:45 · 283 阅读 · 0 评论 -
15.4 Merge Intervals
Link:Approach I: Dai's codeTime: O(1+原创 2014-08-05 08:01:53 · 468 阅读 · 0 评论 -
15.3 Insert Interval
Link: https://oj.leetcode.com/problems/insert-interval/原创 2014-08-05 06:12:42 · 301 阅读 · 0 评论 -
5.4.7 Sum Root to Leaf Numbers
这题不难,但是我还是没写对。再练。public class Solution { int sum = 0; public int sumNumbers(TreeNode root) { if(root == null) if(root.left != null){ sum += root.val * 10 + sumNu原创 2014-07-17 14:11:13 · 259 阅读 · 0 评论 -
6.3 Merge k Sorted Lists
原题链接:https://oj.leetcode.com/problems/merge-k-sorted-lists/Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.原创 2014-07-18 06:07:38 · 374 阅读 · 0 评论 -
2.2.8 Swap Nodes in Pairs
Link: Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only const原创 2014-08-25 05:14:25 · 363 阅读 · 0 评论 -
2.2.7 Remove Nth Node From End of List
Link: https://oj.leetcode.com/problems/remove-nth-node-from-end-of-list/Given a linked list, remove the nth node from the end of list and return its head.For example, Given linked list: 1->2原创 2014-08-25 01:30:53 · 340 阅读 · 0 评论