leetcode
旖旎_Sarah
这个作者很懒,什么都没留下…
展开
-
剑指 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 · 114 阅读 · 0 评论 -
剑指 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 · 91 阅读 · 0 评论 -
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 · 73 阅读 · 0 评论 -
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 · 103 阅读 · 0 评论 -
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 · 66 阅读 · 0 评论 -
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 · 110 阅读 · 0 评论 -
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 · 52 阅读 · 0 评论 -
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 · 81 阅读 · 0 评论 -
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 · 103 阅读 · 0 评论 -
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 · 68 阅读 · 0 评论 -
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 · 92 阅读 · 0 评论 -
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 · 168 阅读 · 0 评论 -
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 · 110 阅读 · 0 评论 -
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 · 78 阅读 · 0 评论 -
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 · 106 阅读 · 0 评论 -
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 · 76 阅读 · 0 评论 -
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 · 147 阅读 · 0 评论 -
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 · 116 阅读 · 0 评论 -
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 · 159 阅读 · 0 评论 -
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 · 146 阅读 · 0 评论 -
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 · 150 阅读 · 0 评论 -
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 · 74 阅读 · 0 评论 -
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 · 85 阅读 · 0 评论 -
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 · 247 阅读 · 0 评论 -
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 · 82 阅读 · 0 评论 -
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 · 79 阅读 · 0 评论 -
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 · 84 阅读 · 0 评论 -
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 · 131 阅读 · 0 评论 -
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 · 74 阅读 · 0 评论 -
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 · 71 阅读 · 0 评论 -
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 · 130 阅读 · 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 · 69 阅读 · 0 评论 -
leetcode学习笔记19
315. Count of Smaller Numbers After SelfInput: [5,2,6,1]Output: [2,1,1,0]Explanation:To the right of 5 there are 2 smaller elements (2 and 1).To the right of 2 there is only 1 smaller element (1)...原创 2018-12-13 20:55:27 · 64 阅读 · 0 评论 -
leetcode学习笔记11
124. Binary Tree Maximum Path SumGiven a non-empty binary tree, find the maximum path sum.For this problem, a path is defined as any sequence of nodes from some starting node to any node in the tree...原创 2018-12-06 11:12:29 · 68 阅读 · 0 评论 -
leetcode学习笔记14
322. Coin ChangeYou are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that...原创 2018-12-08 19:54:41 · 49 阅读 · 0 评论 -
leetcode学习笔记18
108. Convert Sorted Array to Binary Search TreeGiven an array where elements are sorted in ascending order, convert it to a height balanced BST.For this problem, a height-balanced binary tree is def...原创 2018-12-12 14:38:18 · 71 阅读 · 0 评论 -
leetcode学习笔记8
122. Best Time to Buy and Sell Stock IISay you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete as many...原创 2018-12-03 13:24:34 · 64 阅读 · 0 评论 -
leetcode学习笔记10
102. Binary Tree Level Order Traversal(BFS)1、迭代的方法用树的高度控制插入位置class Solution { public List<List<Integer>> levelOrder(TreeNode root) { List<List<Integer>> res=new ...原创 2018-12-05 09:48:58 · 78 阅读 · 0 评论 -
leetcode学习笔记3
20. Valid ParenthesesGiven a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:Open brackets must be closed b...原创 2018-11-28 11:02:35 · 72 阅读 · 0 评论 -
leetcode学习笔记7
227. Basic Calculator IIImplement a basic calculator to evaluate a simple expression string.The expression string contains only non-negative integers, +, -, *, / operators and empty spaces . The int...原创 2018-11-30 20:46:55 · 74 阅读 · 0 评论