- 博客(61)
- 资源 (3)
- 收藏
- 关注
原创 剑指 Offer 04. 二维数组中的查找
剑指 Offer 04. 二维数组中的查找在一个 n * m 的二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/er-wei-shu-zu-zhong-de-cha-zhao-lcof著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。方法1:暴力解法遍历数组时间复杂
2020-07-11 15:07:12 139
原创 剑指 Offer 03. 数组中重复的数字
剑指 Offer 03. 数组中重复的数字在一个长度为 n 的数组 nums 里的所有数字都在 0~n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。请找出数组中任意一个重复的数字。来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/shu-zu-zhong-zhong-fu-de-shu-zi-lcof著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。方法1: 额外空间(自己解题思路
2020-07-10 13:20:59 94
原创 leetcode学习笔记59
5. Longest Palindromic SubstringGiven a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: “babad”Output: “bab”Note: “aba”...
2019-01-31 21:07:50 138
原创 leetcode学习笔记58
300. Longest Increasing SubsequenceGiven an unsorted array of integers, find the length of longest increasing subsequence.Example:Input: [10,9,2,5,3,7,101,18]Output: 4Explanation: The longest inc...
2019-01-31 20:47:08 180
原创 leetcode学习笔记57
Given an integer matrix, find the length of the longest increasing path.From each cell, you can either move to four directions: left, right, up or down. You may NOT move diagonally or move outside of...
2019-01-31 20:08:40 166
原创 leetcode学习笔记56
128. Longest Consecutive SequenceGiven an unsorted array of integers, find the length of the longest consecutive elements sequence.Your algorithm should run in O(n) complexity.Example:Input: [100,...
2019-01-31 19:59:32 168
原创 leetcode学习笔记55
Largest Rectangle in HistogramGiven n non-negative integers representing the histogram’s bar height where the width of each bar is 1, find the area of largest rectangle in the histogram.Above is ...
2019-01-18 13:45:03 80
原创 leetcode学习笔记54
141. Linked List CycleGiven a linked list, determine if it has a cycle in it.To represent a cycle in the given linked list, we use an integer pos which represents the position (0-indexed) in the lin...
2019-01-17 14:22:15 102
原创 leetcode学习笔记53
17. Letter Combinations of a Phone NumberGiven a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (j...
2019-01-17 10:12:13 134
原创 leetcode学习笔记52
179. Largest NumberGiven a list of non negative integers, arrange them such that they form the largest number.Example 1:Input: [10,2]Output: “210”Example 2:Input: [3,30,34,5,9]Output: “9534330”...
2019-01-16 12:18:30 79
原创 leetcode学习笔记51
LRU CacheDesign and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) - Get the value (will always be positive) of th...
2019-01-15 16:46:56 87
原创 leetcode学习笔记50
378. Kth Smallest Element in a Sorted MatrixGiven a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth smallest element in the matrix.Note that it is the kth...
2019-01-14 15:02:18 91
原创 leetcode学习笔记49
230. Kth Smallest Element in a BSTGiven a binary search tree, write a function kthSmallest to find the kth smallest element in it.Note:You may assume k is always valid, 1 ≤ k ≤ BST’s total elements...
2019-01-11 09:52:09 116
原创 leetcode学习笔记48
215. Kth Largest Element in an ArrayFind the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.Example 1:Input: [3,...
2019-01-10 13:54:11 122
原创 leetcode学习笔记47
55. Jump GameGiven an array of non-negative integers, you are initially positioned at the first index of the array.Each element in the array represents your maximum jump length at that position.Det...
2019-01-09 16:48:28 290
原创 leetcode学习笔记46
160. Intersection of Two Linked ListsWrite a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:begin to intersect at ...
2019-01-09 15:49:36 106
原创 leetcode学习笔记45
350. Intersection of Two Arrays IIGiven two arrays, write a function to compute their intersection.Example 1:Input: nums1 = [1,2,2,1], nums2 = [2,2]Output: [2,2]Example 2:Input: nums1 = [4,9,5],...
2019-01-09 10:29:54 105
原创 leetcode学习笔记44
380. Insert Delete GetRandom O(1)Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the set if not already present.remove(val): ...
2019-01-08 12:50:40 151
原创 leetcode学习笔记43
334. Increasing Triplet SubsequenceGiven an unsorted array return whether an increasing subsequence of length 3 exists or not in the array.Formally the function should:Return true if there exists i...
2019-01-07 21:43:18 78
原创 leetcode学习笔记42
28. Implement strStr()Implement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: haystack = “hello”, needle = “ll”...
2019-01-04 03:25:17 119
原创 leetcode学习笔记41
这是一道单词查找树的问题,这里讲的比较详细https://www.cnblogs.com/justinh/p/7716421.htmlclass Trie { class TrieNode { // R links to node children private TrieNode[] links; private final int R = 26; ...
2019-01-04 03:12:03 85
原创 leetcode学习笔记40
198. House RobberYou are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is t...
2019-01-03 23:26:13 111
原创 leetcode学习笔记39
49. Group AnagramsInput: [“eat”, “tea”, “tan”, “ate”, “nat”, “bat”],Output:[[“ate”,“eat”,“tea”],[“nat”,“tan”],[“bat”]]这道题主要用到了HashMap的例子class Solution { public List<List<String>>...
2019-01-03 10:49:43 169
原创 leetcode学习笔记38
22. Generate ParenthesesFor example, given n = 3, a solution set is:[“((()))”,“(()())”,“(())()”,“()(())”,“()()()”]这道题是借鉴网上的思路解出的,主要摘自https://www.1point3acres.com/bbs/thread-172641-1-1.html所...
2019-01-02 10:11:48 68
原创 leetcode学习笔记37
134. Gas StationThere are N gas stations along a circular route, where the amount of gas at station i is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from s...
2019-01-01 15:28:01 85
原创 leetcode学习笔记36
289. Game of LifeAccording to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John Horton Conway in 1970.”Given a ...
2018-12-29 13:57:29 169 1
原创 leetcode学习笔记35
166. Fraction to Recurring DecimalGiven two integers representing the numerator and denominator of a fraction, return the fraction in string format.If the fractional part is repeating, enclose the r...
2018-12-29 11:12:49 73
原创 leetcode学习笔记34
341. Flatten Nested List IteratorGiven a nested list of integers, implement an iterator to flatten it.Each element is either an integer, or a list – whose elements may also be integers or other list...
2018-12-28 10:09:35 83
原创 leetcode学习笔记33
387. First Unique Character in a StringGiven a string, find the first non-repeating character in it and return it’s index. If it doesn’t exist, return -1.class Solution { public int firstUniqCha...
2018-12-27 10:41:19 63
原创 leetcode学习笔记32
41. First Missing PositiveGiven an unsorted integer array, find the smallest missing positive integer.Example 1:Input: [1,2,0]Output: 3Example 2:Input: [3,4,-1,1]Output: 2Example 3:Input: [7,...
2018-12-26 11:11:41 57
原创 leetcode学习笔记31
287. Find the Duplicate NumberGiven an array nums containing n + 1 integers where each integer is between 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there i...
2018-12-25 13:57:02 74
原创 leetcode学习笔记30
295. Find Median from Data StreamMedian is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle value.F...
2018-12-24 20:39:20 195
原创 leetcode学习笔记29
162. Find Peak Elementclass Solution { public int findPeakElement(int[] nums) { int i=0; while(i<nums.length-1&&nums[i+1]>nums[i])i++; return i; }}
2018-12-24 17:17:44 75
原创 leetcode学习笔记27
Given an integer n, return the number of trailing zeroes in n!.Input: 3Output: 0Explanation: 3! = 6, no trailing zero.2*5含有0,每个n都含有2,因此主要统计5的个数就可以了,25即两个5,125即三个5class Solution { public int t...
2018-12-20 19:51:50 58
原创 leetcode学习笔记27
34. Find First and Last Position of Element in Sorted ArrayGiven an array of integers nums sorted in ascending order, find the starting and ending position of a given target value.Your algorithm’s r...
2018-12-20 19:44:18 70
原创 leetcode学习笔记26
171. Excel Sheet Column NumberGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -> 26AA -> 27AB -> ...
2018-12-20 13:33:28 151
原创 leetcode学习笔记25
150. Evaluate Reverse Polish Notationvaluate the value of an arithmetic expression in Reverse Polish Notation.Valid operators are +, -, *, /. Each operand may be an integer or another expression.No...
2018-12-20 10:37:42 136
原创 leetcode学习笔记24
Given two integers dividend and divisor, divide two integers without using multiplication, division and mod operator.Return the quotient after dividing dividend by divisor.The integer division shoul...
2018-12-19 11:20:59 96
原创 leetcode学习笔记23
91. Decode Waysmessage containing letters from A-Z is being encoded to numbers using the following mapping:‘A’ -> 1‘B’ -> 2…‘Z’ -> 26Given a non-empty string containing only digits, det...
2018-12-18 14:07:22 87
原创 leetcode学习笔记22
207. Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is...
2018-12-14 21:50:57 95
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人