算法设计
文章平均质量分 66
chengych
这个作者很懒,什么都没留下…
展开
-
383. Ransom Note
Difficulty:easyGiven an arbitrary ransom note string and another string containing letters from all the magazines, write a function that will return true if the ransom not原创 2016-09-12 23:43:35 · 289 阅读 · 0 评论 -
【leetcode】312. Burst Balloons
Difficulty:HardGiven n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloons. If the you burst ballo原创 2016-09-06 23:12:10 · 276 阅读 · 0 评论 -
【leetcode】35. Search Insert Position
Difficulty:mediumGiven 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 d原创 2016-09-21 09:35:18 · 190 阅读 · 0 评论 -
【leetcode】74. Search a 2D Matrix
Difficulty:mediumWrite 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.Th原创 2016-09-21 09:49:25 · 227 阅读 · 0 评论 -
【leetcode】34. Search for a Range
Difficulty:mediumGiven a sorted array of integers, find the starting and ending position of a given target value.Your algorithm's runtime complexity must be in the order of O(log n).If t原创 2016-09-21 10:28:46 · 285 阅读 · 0 评论 -
【leetcode】4. Median of Two Sorted Arrays
Difficulty:HardThere are two sorted arrays nums1 and nums2 of size m and n respectively.Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).E原创 2016-09-29 23:43:53 · 256 阅读 · 0 评论 -
【leetcode】215. Kth Largest Element in an Array
Difficulty:MediumFind 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原创 2016-09-30 00:36:19 · 306 阅读 · 0 评论 -
【leetcode】75. Sort ColorsD
Difficulty:MediumGiven an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we原创 2016-09-30 00:49:40 · 240 阅读 · 0 评论 -
【leetcode】188. Best Time to Buy and Sell Stock IV
Difficulty:HardSay 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 most k transactions.原创 2016-10-18 22:42:04 · 224 阅读 · 0 评论 -
【leetcode】55. Jump Game
Difficulty:MediumGiven 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 th原创 2016-10-18 23:13:24 · 216 阅读 · 0 评论 -
【leetcode】45. Jump Game II
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.Your goal is原创 2016-10-18 23:32:02 · 233 阅读 · 0 评论 -
【leetcode】33. Search in Rotated Sorted Array
Difficulty:hardSuppose a sorted array 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 found原创 2016-09-20 00:27:18 · 292 阅读 · 0 评论 -
【leetcode】162. Find Peak Element
Difficulty:mediumA 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原创 2016-09-20 00:14:58 · 315 阅读 · 0 评论 -
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.Examples:s = "leetcode"return 0.s = "loveleetcode",return 2.Note:原创 2016-09-12 23:36:28 · 200 阅读 · 0 评论 -
318. Maximum Product of Word Lengths
Difficulty:MediumGiven a string array words, find the maximum value of length(word[i]) * length(word[j]) where the two words do not share common letters. You may assume that each word will原创 2016-09-13 23:53:16 · 325 阅读 · 0 评论 -
【leetcode】80. Remove Duplicates from Sorted Array II
Difficulty:MediumFollow 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原创 2016-09-14 12:04:50 · 195 阅读 · 0 评论 -
【leetcode】120. Triangle
Difficulty:mediumGiven 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[原创 2016-09-14 12:15:46 · 278 阅读 · 0 评论 -
【leetcode】Missing Number
Difficulty:mediumGiven 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:原创 2016-09-05 23:03:06 · 185 阅读 · 0 评论 -
【leetcode】347. Top K Frequent Elements
Difficulty:mediumGiven a non-empty array of integers, return the k most frequent elements.For example,Given [1,1,1,2,2,3] and k = 2, return [1,2].Note: You may assume k is always v原创 2016-09-05 23:17:51 · 344 阅读 · 0 评论 -
【leetcode】167. Two Sum II - Input array is sorted
Difficulty:MediumGiven an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indi原创 2016-09-05 23:34:29 · 303 阅读 · 0 评论 -
【leetcode】121. Best Time to Buy and Sell Stock
Difficulty:Easyay 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原创 2016-10-09 00:40:31 · 186 阅读 · 0 评论 -
【leetcode】122. Best Time to Buy and Sell Stock II
Difficulty:MediumSay 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 transactions原创 2016-10-09 00:46:30 · 186 阅读 · 0 评论 -
【leetcode】123. Best Time to Buy and Sell Stock III
Difficulty:HardSay 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 at most two transac原创 2016-10-09 00:52:11 · 243 阅读 · 0 评论 -
算法概论习题 8.22 NP-完全问题证明
题目:8.22 问题描述: 在任务调度,它常常可以用图进行每个任务的节点和有向边的任务我的任务,如果我是一个先决条件J.这个有向图描绘的优先约束的调度问题。显然,当且仅当图是循环的时,调度是可能的;如果它不是,我们想确定必须丢弃的最小数量的约束,以便使其循环。给定一个有向图G =(V,E),子集E0⊆E称为反馈弧集如果边E0呈现G环的去除。反馈弧集(FAS):给定一个有向图G原创 2017-01-07 21:03:47 · 1023 阅读 · 0 评论