
Leetcode
文章平均质量分 54
zhumingyuan111
这个作者很懒,什么都没留下…
展开
-
Leetcode : 375. Guess Number Higher or Lower II
Guess Number Higher or Lower IIURL : https://leetcode.com/problems/guess-number-higher-or-lower-ii/解题思路:递归的思路是,我可以猜1~n中任意一个数x,然后递归的去猜[1,x) 和(x,n]两段,取他们最大的值。动态规划的思路,自底向上,把长度为[1,2,…,n]的子数组算出来,dp[1]...原创 2019-06-07 08:36:40 · 223 阅读 · 0 评论 -
Leetcode: 148. Sort List
描述:Sort a linked list in O(n log n) time using constant space complexity.URLhttps://leetcode.com/problems/sort-list/description/解释如果时间复杂度是nlogn,则需要使用快速排序或者归并排序的思想,下面给出两种算法代码//归并排序/** * Definition原创 2018-01-06 14:15:57 · 169 阅读 · 0 评论 -
Leetcode: 147. Insertion Sort List
描述:Sort a linked list using insertion sort.URLhttps://leetcode.com/problems/insertion-sort-list/description/解释因为我们的链表是单项的,所以每一次是从头节点向后查找要插入的位置,然后当前节点插入指定位置。代码class Solution { public ListNode insert原创 2018-01-06 14:02:19 · 177 阅读 · 0 评论 -
Leetcode: 149. Max Points on a Line
URLhttps://leetcode.com/problems/max-points-on-a-line/description/描述Given n points on a 2D plane, find the maximum number of points that lie on the same straight line.解题思路遍历所有点,计算出每一个点与其他的点的原创 2018-01-14 23:32:30 · 174 阅读 · 0 评论 -
Leetcode: 164. Maximum Gap
URLhttps://leetcode.com/problems/maximum-gap/description/描述Given an unsorted array, find the maximum difference between the successive elements in its sorted form.Try to solve it in linear time/space.R原创 2018-01-14 21:49:32 · 198 阅读 · 0 评论 -
leetcode:153. Find Minimum in Rotated Sorted Array
URLhttps://leetcode.com/problems/find-minimum-in-rotated-sorted-array/description/描述:Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2原创 2018-01-13 21:58:26 · 275 阅读 · 0 评论 -
Leetcode: Find Minimum in Rotated Sorted Array II
URL:https://leetcode.com/problems/find-minimum-in-rotated-sorted-array-ii/description/描述:Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed?Would this affec原创 2018-01-13 21:53:31 · 322 阅读 · 0 评论 -
Leetcode: 146. LRU Cache
URL:https://leetcode.com/problems/lru-cache/description/描述:Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and put.get(key) -原创 2017-12-24 11:00:55 · 203 阅读 · 0 评论 -
Leetcode:Candy
URLhttps://leetcode.com/problems/candy/description/描述There are N children standing in a line. Each child is assigned a rating value.You are giving candies to these children subjected to the following r原创 2017-12-06 08:37:33 · 252 阅读 · 0 评论 -
Leetcode: Reorder List
url :https://leetcode.com/problems/reorder-list/description/描述Given a singly linked list L: L0→L1→…→Ln-1→Ln, reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→…You must do this in-place without altering the nodes’原创 2017-12-21 23:17:59 · 196 阅读 · 0 评论 -
Leetcode:Word Ladder II
Urlhttps://leetcode.com/submissions/detail/129718140/描述Given two words (beginWord and endWord), and a dictionary’s word list, find all shortest transformation sequence(s) from beginWord to endWord, suc原创 2017-11-26 22:33:00 · 259 阅读 · 0 评论 -
Leetcode:Gas Station
URLhttps://leetcode.com/problems/gas-station/description/描述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原创 2017-12-06 08:35:23 · 328 阅读 · 1 评论 -
Leetcode:Palindrome Partitioning & Palindrome Partitioning II
Palindrome PartitioningURLhttps://leetcode.com/problems/palindrome-partitioning/description/描述Given a string s, partition s such that every substring of the partition is a palindrome.Return all possibl原创 2017-12-03 21:22:30 · 200 阅读 · 0 评论 -
Leetcode:Longest Consecutive Sequence
URLhttps://leetcode.com/problems/longest-consecutive-sequence/description/描述Given an unsorted array of integers, find the length of the longest consecutive elements sequence.For example, Given [100, 4原创 2017-12-02 12:48:04 · 215 阅读 · 0 评论 -
Leetcode:174. Dungeon Game
URLhttps://leetcode.com/problems/dungeon-game/description/描述The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid原创 2018-02-03 22:36:12 · 170 阅读 · 0 评论 -
Leetcode: 220. Contains Duplicate III
URLhttps://leetcode.com/problems/contains-duplicate-iii/description/描述Given an array of integers, find out whether there are two distinct indices i and j in the array such that the absolute difference原创 2018-03-03 12:59:06 · 163 阅读 · 0 评论 -
Leetcode:214. Shortest Palindrome
URLhttps://leetcode.com/problems/shortest-palindrome/description/描述Given a string S, you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest pali原创 2018-02-25 13:59:04 · 214 阅读 · 0 评论 -
Leetcode: 992. Subarrays with K Different Integers
URL : https://leetcode.com/problems/subarrays-with-k-different-integers/思路:该题其实代码量不多,但是思路不好想,我是看了discuss才恍然大悟。下面给出代码。数组中最多出现K个不同的数字的组合数为N, 数组中最多出现K-1个不同的数字的组合数为M,则我们想要的结果是出现K个不同的组合数N-M.最多出现K个不同的数字...原创 2019-05-26 10:25:32 · 437 阅读 · 0 评论 -
Leetcode: Longest Substring Without Repeating Characters
URL : https://leetcode.com/problems/longest-substring-without-repeating-characters/思路:思路就是滑动窗口,当前字符在之前没有出现过,则窗口左端和右端都有效,如果出现重复,则移动窗口的左端直到当前位置的字符在字符串[left, current-1]中没有出现过,在变化的过程中记录最大的长度。下面给出代码。代码:...原创 2019-05-26 10:11:16 · 229 阅读 · 0 评论 -
Leetcode: 315. Count of Smaller Numbers After Self
Url : https://leetcode.com/problems/count-of-smaller-numbers-after-self/You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i...原创 2019-03-31 20:00:24 · 216 阅读 · 0 评论 -
Leetcode:297. Serialize and Deserialize Binary Tree
url https://leetcode.com/problems/serialize-and-deserialize-binary-tree/本题使用层次遍历就行了,下面给出代码/** * Definition for a binary tree node. */ static public class TreeNode { int val;...原创 2019-03-11 23:50:16 · 138 阅读 · 0 评论 -
Leetcode 295 Find Median from Data Stream
题目链接:https://leetcode.com/problems/find-median-from-data-stream/解题思路既然是是找到中位数,我们就使用两个堆,一个是大顶堆,一个小顶堆,保证两个堆满足以下条件:大顶堆的第一个元素需要小于小顶堆的第一个元素;大顶堆的元素数量不能小于小顶堆且最多只能多一个元素;满足以上条件,需要找中位数的时候,判断大顶堆是否比小顶堆元素多,如...原创 2019-03-02 13:24:19 · 159 阅读 · 0 评论 -
Leetcode: 241. Different Ways to Add Parentheses
题目链接https://leetcode.com/problems/different-ways-to-add-parentheses/描述Given a string of numbers and operators, return all possible results from computing all the different possible ways to group nu...原创 2019-02-11 20:06:01 · 198 阅读 · 0 评论 -
218. The Skyline Problem
题目链接 : https://leetcode.com/problems/the-skyline-problem/解题思路先定义下:对于三元组(left,right,high)我们可以认为(left,high)为开始的先计为(left,high,true)(right,high) 认为结束的点,计为(right,high,false),把数据整理为如上格式之后,把输入的点处理一下,保证排顺...原创 2019-01-19 21:51:44 · 174 阅读 · 0 评论 -
Leetcode 289. Game of Life
题目描述Game of LifeMedium647131FavoriteShareAccording to the Wikipedia’s article: “The Game of Life, also known simply as Life, is a cellular automaton devised by the British mathematician John ...原创 2019-01-06 11:52:14 · 404 阅读 · 0 评论 -
Leetcode 284. Peeking Iterator
题目描述Given an Iterator class interface with methods: next() and hasNext(), design and implement a PeekingIterator that support the peek() operation – it essentially peek() at the element that will be ...原创 2019-01-06 10:18:41 · 167 阅读 · 0 评论 -
Leetcode 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 is only one duplicate numbe...原创 2019-01-06 10:15:59 · 231 阅读 · 1 评论 -
Leetcode 324 Wiggle Sort II
题目描述Given an unsorted array nums, reorder it such that nums[0] < nums[1] > nums[2] < nums[3]…Example 1:Input: nums = [1, 5, 1, 1, 6, 4]Output: One possible answer is [1, 4, 1, 5, 1, 6].E...原创 2018-12-30 16:58:17 · 166 阅读 · 0 评论 -
Leetcode:239. Sliding Window Maximum
Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window m...原创 2018-12-06 09:19:37 · 190 阅读 · 0 评论 -
leetcode:best time buy and sell stock系列
best time buy and sell stock系列最近把leetcode上“best time buy and sell stock”系列一共5个问题整理了一下,题目就补贴出来了,在leetcode上面就能找到。best time buy and sell stock 1public int maxProfit(int[] prices) { if (prices=...原创 2018-10-02 22:42:25 · 210 阅读 · 0 评论 -
Leetcode:Sum Root to Leaf Numbers
URLhttps://leetcode.com/problems/sum-root-to-leaf-numbers/description/描述Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-le原创 2017-12-02 12:45:45 · 181 阅读 · 0 评论 -
Leetcode: Surrounded Regions
urlhttps://leetcode.com/problems/surrounded-regions/description/描述Given a 2D board containing ‘X’ and ‘O’ (the letter O), capture all regions surrounded by ‘X’.A region is captured by flipping all ‘O’s原创 2017-12-02 12:39:25 · 214 阅读 · 0 评论 -
Leetcode:Copy List with Random Pointer
URL:https://leetcode.com/problems/copy-list-with-random-pointer/description/描述:A linked list is given such that each node contains an additional random pointer which could point to any node in the list原创 2017-12-09 20:10:05 · 221 阅读 · 0 评论 -
Leetcode : Subsets II
URL:https://leetcode.com/problems/subsets-ii/#/description题目大意:Given a collection of integers that might contain duplicates, nums, return all possible subsets.Note: The solution set must not contain du原创 2017-07-02 09:13:02 · 295 阅读 · 0 评论 -
Leetcode: Remove Duplicates from Sorted List II
url :https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/#/description题目描述Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from th原创 2017-07-02 08:21:56 · 241 阅读 · 0 评论 -
Leetcode: Gray Code
URLhttps://leetcode.com/problems/gray-code/#/description描述The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the tot原创 2017-07-11 07:37:56 · 252 阅读 · 0 评论 -
Leetcode: Search in Rotated Sorted Array & II
URLhttps://leetcode.com/problems/search-in-rotated-sorted-array/#/description描述Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., 0 1 2 4 5 6 7 might b原创 2017-06-17 21:52:12 · 258 阅读 · 0 评论 -
Leetcode: Majority Element &Majority Element II
Majority Element链接https://leetcode.com/problems/majority-element/#/description描述Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ t原创 2017-06-05 08:53:42 · 257 阅读 · 0 评论 -
Leetcode:Insert Delete GetRandom O(1)
链接:https://leetcode.com/problems/insert-delete-getrandom-o1/#/description题目描述:Design a data structure that supports all following operations in average O(1) time.insert(val): Inserts an item val to the原创 2017-06-05 08:26:46 · 216 阅读 · 0 评论 -
Leetcode:Word Ladder
url:https://leetcode.com/problems/word-ladder/#/description题目大意:Given two words (beginWord and endWord), and a dictionary’s word list, find the length of shortest transformation sequence from beginWord原创 2017-05-13 12:17:59 · 259 阅读 · 0 评论