- 博客(20)
- 收藏
- 关注
原创 算法概论证明题
题目: 若有一个图,其顶点数为偶数(比如2n),且其中的n个顶点构成一个团,其余的n个顶点则有一条称为“尾巴”的路径连接,尾巴的某个端点与团中一个顶点相连,这样的图称为“风筝图”。现给定一个图G和目标g,风筝图问题的目标是求出该图的一个包含2g个顶点的风筝子图。请证明该问题是NP-完全的。证明: 我们可以将团问题归约到风筝图问题。团问题的目标是求出某图的一个
2017-07-05 16:46:52
368
原创 Rotate Array
题面:Rotate an array of n elements to the right by k steps.For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4].Note:Try to come up as many solution
2017-07-05 16:33:57
173
原创 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 numbe
2017-07-05 16:10:12
198
原创 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 need
2017-07-05 15:59:45
167
原创 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 d
2017-06-09 09:42:55
277
原创 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 num
2017-06-08 15:47:33
149
原创 216. 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.Example 1:
2017-06-06 17:36:33
145
原创 Two Sum II - Input array is sorted
题面:Given 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 indices of the two
2017-06-06 16:25:13
127
原创 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 a
2017-06-05 15:25:01
140
原创 第十一周作业: 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 wit
2017-06-04 12:50:14
161
原创 第十周作业: Add Digits
题面:Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.For example:Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 h
2017-06-01 15:45:03
191
原创 第九周作业:Fizz Buzz
题面:Write a program that outputs the string representation of numbers from 1 to n.But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz
2017-06-01 14:41:27
323
原创 第八周作业:Reverse Words in a String III
题面:Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode
2017-05-31 17:55:41
266
原创 第七周作业: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
2017-05-31 17:10:32
180
原创 第六周作业:Total Hamming Distance
题目:The Hamming distance between two integers is the number of positions at which the corresponding bits are different.Now your job is to find the total Hamming distance between all pairs of
2017-03-28 18:35:21
164
原创 第五周作业:Single Number III
题目:Given an array of numbers nums, in which exactly two elements appear only once and all the other elements appear exactly twice. Find the two elements that appear only once.For example:
2017-03-28 13:31:51
268
原创 第四周作业:Integer Replacement
题目:Given a positive integer n and you can do operations as follow:If n is even, replace n with n/2.If n is odd, you can replace n with either n + 1 or n - 1.What is the minimum n
2017-03-20 11:34:49
137
原创 第三周作业:位运算
题目:Given a positive integer, output its complement number. The complement strategy is to flip the bits of its binary representation.Note:The given integer is guaranteed to fit within the range
2017-03-10 11:34:10
212
原创 第二周作业:roman to integer
题目:Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999.代码:class Solution {public: int romanToInt(string s) { int i; int
2017-03-04 23:22:15
221
原创 第一周作业:11 container with most water
题目:Given n non-negative integers a1,a2, ..., an, where each represents a point at coordinate (i,ai). n vertical lines are drawn such that the two endpoints of linei is at (i, ai) and (i, 0). F
2017-02-25 22:11:57
203
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人