- 博客(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
201
原创 剑指 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
138
原创 leetcode学习笔记59
5. Longest Palindromic Substring Given 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
180
原创 leetcode学习笔记58
300. Longest Increasing Subsequence Given an unsorted array of integers, find the length of longest increasing subsequence. Example: Input: [10,9,2,5,3,7,101,18] Output: 4 Explanation: The longest inc...
2019-01-31 20:47:08
251
原创 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
213
原创 leetcode学习笔记56
128. Longest Consecutive Sequence Given 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
207
原创 leetcode学习笔记55
Largest Rectangle in Histogram Given 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
124
原创 leetcode学习笔记54
141. Linked List Cycle Given 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
148
原创 leetcode学习笔记53
17. Letter Combinations of a Phone Number Given 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
193
原创 leetcode学习笔记52
179. Largest Number Given 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
115
原创 leetcode学习笔记51
LRU Cache Design 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
130
原创 leetcode学习笔记50
378. Kth Smallest Element in a Sorted Matrix Given 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
138
原创 leetcode学习笔记49
230. Kth Smallest Element in a BST Given 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
154
原创 leetcode学习笔记48
215. Kth Largest Element in an Array Find 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
171
原创 leetcode学习笔记47
55. Jump Game Given 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
364
原创 leetcode学习笔记46
160. Intersection of Two Linked Lists Write 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
150
原创 leetcode学习笔记45
350. Intersection of Two Arrays II Given 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
153
原创 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
203
原创 leetcode学习笔记43
334. Increasing Triplet Subsequence Given 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
118
原创 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
164
原创 leetcode学习笔记41
这是一道单词查找树的问题, 这里讲的比较详细 https://www.cnblogs.com/justinh/p/7716421.html class Trie { class TrieNode { // R links to node children private TrieNode[] links; private final int R = 26; ...
2019-01-04 03:12:03
123
原创 leetcode学习笔记40
198. House Robber You 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
158
原创 leetcode学习笔记39
49. Group Anagrams Input: [“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
216
原创 leetcode学习笔记38
22. Generate Parentheses For example, given n = 3, a solution set is: [ “((()))”, “(()())”, “(())()”, “()(())”, “()()()” ] 这道题是借鉴网上的思路解出的,主要摘自 https://www.1point3acres.com/bbs/thread-172641-1-1.html 所...
2019-01-02 10:11:48
111
原创 leetcode学习笔记37
134. Gas Station There 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
130
原创 leetcode学习笔记36
289. Game of Life According 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
221
1
原创 leetcode学习笔记35
166. Fraction to Recurring Decimal Given 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
114
原创 leetcode学习笔记34
341. Flatten Nested List Iterator Given 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
126
原创 leetcode学习笔记33
387. First Unique Character in a String Given 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
91
原创 leetcode学习笔记32
41. First Missing Positive Given an unsorted integer array, find the smallest missing positive integer. Example 1: Input: [1,2,0] Output: 3 Example 2: Input: [3,4,-1,1] Output: 2 Example 3: Input: [7,...
2018-12-26 11:11:41
107
原创 leetcode学习笔记31
287. Find the Duplicate Number Given 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
119
原创 leetcode学习笔记30
295. Find Median from Data Stream Median 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
243
原创 leetcode学习笔记29
162. Find Peak Element class 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
112
原创 leetcode学习笔记27
Given an integer n, return the number of trailing zeroes in n!. Input: 3 Output: 0 Explanation: 3! = 6, no trailing zero. 2*5含有0,每个n都含有2,因此主要统计5的个数就可以了,25即两个5,125即三个5 class Solution { public int t...
2018-12-20 19:51:50
98
原创 leetcode学习笔记27
34. Find First and Last Position of Element in Sorted Array Given 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
103
原创 leetcode学习笔记26
171. Excel Sheet Column Number Given a column title as appear in an Excel sheet, return its corresponding column number. For example: A -> 1 B -> 2 C -> 3 ... Z -> 26 AA -> 27 AB -> ...
2018-12-20 13:33:28
209
原创 leetcode学习笔记25
150. Evaluate Reverse Polish Notation valuate 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
193
原创 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
148
原创 leetcode学习笔记23
91. Decode Ways message containing letters from A-Z is being encoded to numbers using the following mapping: ‘A’ -> 1 ‘B’ -> 2 … ‘Z’ -> 26 Given a non-empty string containing only digits, det...
2018-12-18 14:07:22
118
原创 leetcode学习笔记22
207. Course Schedule There 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
136
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅