![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
文章平均质量分 56
卯时喝凉水
但求耕耘,不问收获。
展开
-
LeetCode 153. Find Minimum in Rotated Sorted Array
问题描述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 become 4 5 6 7 0 1 2).Find the minimum element.You may assume no duplicate e原创 2017-09-22 10:21:11 · 190 阅读 · 0 评论 -
LeetCode 532. K-diff Pairs in an Array
问题描述Given an array of integers and an integer k, you need to find the number of unique k-diff pairs in the array. Here a k-diff pair is defined as an integer pair (i, j), where i and j are both numbers原创 2017-10-08 10:30:47 · 299 阅读 · 0 评论 -
LeetCode 670. Maximum Swap
问题描述Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get.Example 1: Input: 2736 Output: 7236 Exp原创 2017-09-21 17:18:18 · 442 阅读 · 0 评论 -
LeetCode 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.For example, Given [3,2,1,5,6,4] and k = 2, return 5.No原创 2017-10-08 09:50:26 · 208 阅读 · 0 评论 -
LeetCode 414. Third Maximum Number
问题描述Given a non-empty array of integers, return the third maximum number in this array. If it does not exist, return the maximum number. The time complexity must be in O(n). Example 1: Input: [3, 2,原创 2017-09-28 16:43:29 · 166 阅读 · 0 评论 -
LeetCode 81. Search in Rotated Sorted Array II
问题描述 Follow up for “Search in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why?Suppose an array sorted in ascending order is rota原创 2017-09-19 17:46:02 · 311 阅读 · 0 评论 -
LeetCode 605. Can Place Flowers
问题描述Suppose you have a long flowerbed in which some of the plots are planted and some are not. However, flowers cannot be planted in adjacent plots - they would compete for water and both would die.Giv原创 2017-09-02 17:02:00 · 208 阅读 · 0 评论 -
LeetCode 643. Maximum Average Subarray I
问题描述Given an array consisting of n integers, find the contiguous subarray of given length k that has the maximum average value. And you need to output the maximum average value. Example 1: Input: [1原创 2017-09-02 16:51:47 · 183 阅读 · 0 评论 -
LeetCode 1. Two Sum
问题描述:Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the sam原创 2017-09-02 14:31:03 · 171 阅读 · 0 评论 -
LeetCode 121. Best Time to Buy and Sell Stock
问题描述:Say you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock),原创 2017-09-02 12:09:42 · 163 阅读 · 0 评论 -
LeetCode 565. Array Nesting
问题描述:A zero-indexed array A consisting of N different integers is given. The array contains all integers in the range [0, N - 1].Sets S[K] for 0 <= K < N are defined as follows:S[K] = { A[K], A[A[K]],原创 2017-09-01 18:31:14 · 213 阅读 · 0 评论 -
LeetCode 268. Missing Number
问题描述Given an array containing n distinct numbers taken from 0, 1, 2, …, n, find the one that is missing from the array.For example, Given nums = [0, 1, 3] return 2.Note: Your algorithm should run in原创 2017-10-10 19:34:27 · 153 阅读 · 0 评论 -
LeetCode 118. Pascal's Triangle
问题描述Given numRows, generate the first numRows of Pascal’s triangle.For example, given numRows = 5, Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ]题目描述杨辉三角,一个数等于他肩上的两个数的和。两原创 2017-10-10 19:38:31 · 190 阅读 · 0 评论 -
LeetCode 119. Pascal's Triangle II
问题描述Given an index k, return the kth row of the Pascal’s triangle.For example, given k = 3, Return [1,3,3,1].Note: Could you optimize your algorithm to use only O(k) extra space?题目描述给定一个数,返回杨辉三角中对应的行原创 2017-10-11 19:18:54 · 161 阅读 · 0 评论 -
LeetCode 147. Insertion Sort List
问题描述https://leetcode.com/problems/insertion-sort-list/description/ Sort a linked list using insertion sort.问题分析给定一个链表,对这个链表进行插入排序。 步骤: 第一个:是从原有的链表中取出一个节点。 第二步:在排序后的链表中找出对应节点的位置 第三步:将取出的节点原创 2018-01-20 22:34:00 · 150 阅读 · 0 评论 -
LeetCode 524. Longest Word in Dictionary through Deleting
问题描述https://leetcode.com/problems/longest-word-in-dictionary-through-deleting/description/Given a string and a string dictionary, find the longest string in the dictionary that can be formed by de原创 2018-01-20 20:51:46 · 171 阅读 · 0 评论 -
LeetCode 274. H-Index
问题描述https://leetcode.com/problems/h-index/description/ Given an array of citations (each citation is a non-negative integer) of a researcher, write a function to compute the researcher’s h-index.原创 2018-01-19 14:40:07 · 222 阅读 · 0 评论 -
LeetCode 148. Sort List
问题描述https://leetcode.com/problems/sort-list/description/ Sort a linked list in O(n log n) time using constant space complexity. 使用空间复杂度为常量,时间复杂度为 O(nlgn)对链表进行排序。问题分析排序的算法复杂度为O(nlgn)的有三种,快速排序,堆原创 2018-01-21 18:21:59 · 196 阅读 · 0 评论 -
LeetCode 179. Largest Number
问题描述https://leetcode.com/problems/largest-number/description/ Given a list of non negative integers, arrange them such that they form the largest number.For example, given [3, 30, 34, 5, 9], the原创 2018-01-21 15:00:46 · 211 阅读 · 0 评论 -
LeetCode 283. Move Zeroes
问题描述Given an array nums, write a function to move all 0’s to the end of it while maintaining the relative order of the non-zero elements.For example, given nums = [0, 1, 0, 3, 12], after calling your f原创 2017-10-14 15:29:34 · 231 阅读 · 0 评论 -
LeetCode 53. Maximum Subarray
问题描述Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [-2,1,-3,4,-1,2,1,-5,4], the contiguous subarray [4,-1,2,1] has原创 2017-10-14 15:05:58 · 208 阅读 · 0 评论 -
LeetCode 561. Array Partition I
问题描述Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), …, (an, bn) which makes sum of min(ai, bi) for all i from 1 to n as large as pos原创 2017-10-14 14:15:51 · 194 阅读 · 0 评论 -
LeetCode 566. Reshape the Matrix
问题描述In MATLAB, there is a very useful function called ‘reshape’, which can reshape a matrix into a new one with different size but keep its original data.You’re given a matrix represented by a two-dime原创 2017-10-14 13:40:24 · 187 阅读 · 0 评论 -
LeetCode 66. Plus One
问题描述Given a non-negative integer represented as a non-empty array of digits, plus one to the integer.You may assume the integer do not contain any leading zero, except the number 0 itself.The digits ar原创 2017-10-11 19:32:36 · 206 阅读 · 0 评论 -
LeetCode 674. Longest Continuous Increasing Subsequence
问题描述Given an unsorted array of integers, find the length of longest continuous increasing subsequence. Example 1: Input: [1,3,5,4,7] Output: 3 Explanation: The longest continuous increasing subsequ原创 2017-10-11 19:23:16 · 210 阅读 · 0 评论 -
LeetCode 80. Remove Duplicates from Sorted Array II
问题描述Follow up for “Remove Duplicates”: What if duplicates are allowed at most twice?For example, Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first five el原创 2017-09-18 20:09:09 · 412 阅读 · 0 评论 -
LeetCode 219. Contains Duplicate II
问题描述:Given an array of integers and an integer k, find out whether there are two distinct indices i and j in the array such that nums[i] = nums[j] and the absolute difference between i and j is at most原创 2017-09-01 15:22:04 · 249 阅读 · 0 评论 -
LeetCode 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): Removes an item v原创 2017-08-27 15:10:54 · 248 阅读 · 0 评论 -
LeetCode 31. Next Permutation
问题描述Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the low原创 2017-08-28 17:00:26 · 187 阅读 · 0 评论 -
LeetCode 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 board with m by原创 2017-09-24 14:55:56 · 191 阅读 · 0 评论 -
LeetCode 120. Triangle
问题描述Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle > [ [2], [3,4原创 2017-09-07 15:24:20 · 176 阅读 · 0 评论 -
LeetCode 73. Set Matrix Zeroes
问题描述Given a m x n matrix, if an element is 0, set its entire row and column to 0. Do it in place. Follow up: Did you use extra space? A straight forward solution using O(mn) space is probably a bad原创 2017-09-07 15:08:02 · 202 阅读 · 0 评论 -
LeetCode 79. Word Search
问题描述Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where “adjacent” cells are those horizontally or vertically原创 2017-09-23 12:31:37 · 179 阅读 · 0 评论 -
LeetCode 209. Minimum Size Subarray Sum
问题描述Given an array of n positive integers and a positive integer s, find the minimal length of a contiguous subarray of which the sum ≥ s. If there isn’t one, return 0 instead.For example, given the ar原创 2017-09-06 11:24:16 · 254 阅读 · 0 评论 -
LeetCode 229. Majority Element II
问题描述Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space.问题分析给定一个数组,当前数组中所有的出现次数超过1/3的值。做法了之前的求超过一半的值的做法有些类原创 2017-09-05 12:28:42 · 202 阅读 · 0 评论 -
LeetCode 238. Product of Array Except Self
问题描述Given an array of n integers where n > 1, nums, return an array output such that output[i] is equal to the product of all the elements of nums except nums[i].Solve it without division and in O(n).F原创 2017-09-05 12:23:18 · 182 阅读 · 0 评论 -
LeetCode 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.Determine if you原创 2017-09-05 11:31:18 · 169 阅读 · 0 评论 -
LeetCode 54. Spiral Matrix
问题描述Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example, Given the following matrix: [ [ 1, 2, 3 ], [ 4, 5, 6原创 2017-09-05 10:52:22 · 211 阅读 · 0 评论 -
LeetCode 661. Image Smoother
题目描述Given a 2D integer matrix M representing the gray scale of an image, you need to design a smoother to make the gray scale of each cell becomes the average gray scale (rounding down) of all the原创 2017-08-27 13:46:31 · 1309 阅读 · 0 评论 -
LeetCode 169. Majority Element
问题:Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority e原创 2017-08-30 12:57:42 · 198 阅读 · 0 评论