
leetcode
文章平均质量分 71
xu2645318400
这个作者很懒,什么都没留下…
展开
-
leetcode之Contains Duplicate 问题
问题描述:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if every ele原创 2017-07-11 17:22:23 · 262 阅读 · 0 评论 -
leetcode之Contains Duplicate II 问题
问题描述:Given an array of integers and an integer k, find out whether there are two distinct indicesi andj in the array such that nums[i] = nums[j] and the absolute difference betweeni andj is at m原创 2017-07-11 19:48:03 · 336 阅读 · 0 评论 -
leetcode之Find All Duplicates in an Array 问题
问题描述:Given an array of integers, 1 ≤ a[i] ≤ n (n = size of array),some elements appear twice and others appear once.Find all the elements that appear twice in this array.Could you do it withou原创 2017-07-11 20:23:29 · 272 阅读 · 0 评论 -
leetcode之 Find All Numbers Disappeared in an Array 问题
问原创 2017-07-11 20:43:07 · 707 阅读 · 0 评论 -
leetcode之Remove Duplicates from Sorted Array 问题
问题描述:Given a sorted array(注意题目给的是已经排好序的数组), remove the duplicates in place such that each element appear onlyonce and return the new length.Do not allocate extra space for another array, you must原创 2017-07-03 16:34:29 · 455 阅读 · 0 评论 -
leetcode之Best Time to Buy and Sell Stock II问题
问题描述:Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete as many transactions as you like(ie, b原创 2017-07-04 20:25:36 · 371 阅读 · 0 评论 -
leetcode之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 dayi.If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the s原创 2017-07-04 19:51:25 · 463 阅读 · 0 评论 -
leetcode之Best Time to Buy and Sell Stock III 问题
问题描述:Say you have an array for which the ith element is the price of a given stock on dayi.Design an algorithm to find the maximum profit. You may complete at mosttwo transactions.(发现这些问题变化了啥没?)原创 2017-07-04 20:45:43 · 266 阅读 · 0 评论 -
leetcode之Find Minimum in Rotated Sorted Array II 问题
问题描述:Follow up for "Find Minimum 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原创 2017-07-15 16:16:19 · 353 阅读 · 0 评论 -
leetcode之Find Peak Element 问题
问题描述:A peak element is an element that is greater than its neighbors.Given an input array where num[i] ≠ num[i+1], find a peak element and return its index.The array may contain multiple peaks原创 2017-07-15 18:43:45 · 260 阅读 · 0 评论 -
leetcode之Find the Duplicate Number 问题
问题描述:Given an array nums containing n + 1 integers where each integer isbetween 1 and n (inclusive), prove that at least one duplicate number must exist. Assume that there is only one duplicate nu原创 2017-07-15 19:22:51 · 423 阅读 · 0 评论 -
leetcode之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原创 2017-07-15 15:44:28 · 314 阅读 · 0 评论 -
leetcode之First Missing Positive 问题
问题描述:Given an unsorted integer array, find the first missing positive integer. For example,Given [1,2,0] return 3,and [3,4,-1,1] return 2. Your algorithm should run in O(n) time and uses con原创 2017-07-15 20:16:10 · 353 阅读 · 0 评论 -
leetcode之Combination Sum 问题
问题描述:Given a set of candidate numbers (C) (without duplicates) and a target number (T), find all unique combinations inC where the candidate numbers sums toT.The same repeated number may be chos原创 2017-07-07 09:15:18 · 359 阅读 · 0 评论 -
leetcode之Combination Sum II 问题
问题描述:Given a collection of candidate numbers (C) and a target number (T), find all unique combinations inC where the candidate numbers sums toT.Each number in C may only be used once in the comb原创 2017-07-07 16:14:26 · 374 阅读 · 0 评论 -
leetcode之Combination Sum III 问题
问题描述:Find all possible combinations of k numbers that add up to a number n, given that only numbers from 1 to 9 can be used and each combination should be a unique set of numbers.(就是要求你从1~9之间找到K个数原创 2017-07-07 16:29:57 · 314 阅读 · 0 评论 -
leetcode之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 abo原创 2017-07-17 09:03:29 · 479 阅读 · 0 评论 -
leetcode之Construct Binary Tree from Inorder and Postorder Traversal 问题
问题描述:Given inorder and postorder traversal of a tree, construct the binary tree.Note:You may assume that duplicates do not exist in the tree. 啰嗦一句,可能学过数据结构的人看到题目就知道啥意思了,给的问题介绍和描述几乎没啥意思。示例:原创 2017-07-08 18:25:54 · 670 阅读 · 0 评论 -
leetcode之Construct Binary Tree from Preorder and Inorder Traversal 问题
问题描述:Given preorder and inorder traversal of a tree, construct the binary tree.(意思很简单,给出先序和中序遍历的序列,构造出这棵二叉树)Note:You may assume that duplicates do not exist in the tree. 示例:其实这个图我在上一篇文章就给出了,原创 2017-07-09 10:39:15 · 223 阅读 · 0 评论 -
leetcode之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 val fr原创 2017-07-25 20:40:03 · 295 阅读 · 0 评论 -
leetcode之Insert Interval 问题
问题描述:Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if necessary).You may assume that the intervals were initially sorted according to their start time原创 2017-07-25 20:58:09 · 327 阅读 · 0 评论 -
leetcode之Remove Element
问题描述:Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memo原创 2017-07-03 17:00:42 · 247 阅读 · 0 评论 -
Leetcode之Rotate Image 问题
问题描述:You are given an n x n 2D matrix representing an image.Rotate the image by 90 degrees (clockwise).Note:You have to rotate the image in-place, which means you have to modify the input 2D原创 2017-09-23 09:52:49 · 233 阅读 · 0 评论 -
Leetcode之Search Insert Position 问题
问题描述:Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the原创 2017-09-23 10:07:54 · 158 阅读 · 0 评论 -
Leetcode之Search a 2D Matrix 问题
问题描述:Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted from left to right.The first in原创 2017-09-23 10:18:14 · 210 阅读 · 0 评论 -
Leetcode之Search for a Range 问题
问题描述:Given an array of integers sorted in ascending order, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(logn).I原创 2017-09-23 10:34:31 · 441 阅读 · 0 评论 -
Leetcode之Rotate Array 问题
问题描述:Rotate an array of n elements to the right by k steps.Note:Try to come up as many solutions as you can, there are at least 3 different ways to solve this problem.示例:For example, with原创 2017-09-22 22:02:50 · 233 阅读 · 0 评论 -
Leetcode之Search 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).You are given a target value to search. If f原创 2017-09-23 14:37:55 · 222 阅读 · 0 评论 -
Leetcode之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 rotate原创 2017-09-23 15:32:07 · 239 阅读 · 0 评论 -
Leetcode之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原创 2017-09-23 15:57:48 · 254 阅读 · 0 评论 -
Leetcode之Shortest Unsorted Continuous Subarray 问题
问题描述:Given an integer array, you need to find one continuous subarray that if you only sort this subarray in ascending order, then the whole array will be sorted in ascending order, too.You ne原创 2017-09-23 16:23:58 · 175 阅读 · 0 评论 -
Leetcode之Sort Colors 问题
问题描述:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with thecolors in the order red, white and blue. Here, we will use the in原创 2017-09-23 17:04:52 · 279 阅读 · 0 评论 -
Leetcode之Subarray Sum Equals K问题
问题描述:Given an array of integers and an integer k, you need to find the total number ofcontinuous subarrays whose sum equals to k.Note:The length of the array is in range [1, 20,000].The ra原创 2017-09-23 21:41:47 · 519 阅读 · 0 评论 -
Leetcode之Subsets 问题
问题描述:Given a set of distinct integers, nums, return all possible subsets.Note: The solution set must not contain duplicate subsets.示例:For example,If nums = [1,2,3], a solution is: [ [3]原创 2017-09-24 14:41:30 · 294 阅读 · 0 评论 -
Leetcode之Subsets II 问题
问题描述:Given a collection of integers that might contain duplicates,nums, return all possible subsets.Note: The solution set must not contain duplicate subsets. 示例:For example,If nums = [1,2原创 2017-09-24 15:22:55 · 195 阅读 · 0 评论 -
Leetcode之Summary Ranges 问题
问题描述:Given a sorted integer array without duplicates, return the summary of its ranges.示例一:Input: [0,1,2,4,5,7]Output: ["0->2","4->5","7"]示例二:Input: [0,2,3,4,6,8,9]Output: ["0","2->4","6原创 2017-09-24 15:55:55 · 214 阅读 · 0 评论 -
Leetocode之Task Scheduler 问题
问题描述:Given a char array representing tasks CPU need to do. It contains capital letters A to Z where different letters represent different tasks.Tasks could be done without original order. Each tas原创 2017-09-24 16:20:14 · 251 阅读 · 0 评论 -
Leetcode之Teemo Attacking 问题
问题描述:In LOL world, there is a hero called Teemo and his attacking can make his enemy Ashe be in poisoned condition. Now, given the Teemo's attackingascending time series towards Ashe and the poiso原创 2017-09-24 16:57:08 · 247 阅读 · 0 评论 -
Leetcode之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).示例一:Input: [3, 2, 1]原创 2017-09-24 19:11:18 · 421 阅读 · 0 评论 -
Leetcode之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.Note:Bonus point if you are able to do this using only O(n) extra原创 2017-09-24 19:26:55 · 405 阅读 · 0 评论