- 博客(14)
- 收藏
- 关注
原创 算法概论第8章习题
8.3问题描述:STINGY SAT is the following problem: given a set of clauses(each a disjunction of literals) and an integer k, find a satisfying assignment in which at most k variables are true, if such an assi
2017-01-11 20:45:46
581
原创 Merge Intervals - leetcode 56号题目个人题解
题目要求Given a collection of intervals, merge all overlapping intervals.For example, Given [1,3],[2,6],[8,10],[15,18], return [1,6],[8,10],[15,18].解题思路这道题的意思十分地简单明了,就是题目给出一些区间,我们要把这些区间合并成一个个没有交集的区间。 我们
2016-12-19 16:05:15
380
原创 Triangle - leetcode 120号题目个人题解
题目要求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], [6,5,7
2016-11-20 23:48:34
377
原创 Unique Binary Search Trees - leecode 96号题目个人题解
题目要求Given n, how many structurally unique BST’s (binary search trees) that store values 1…n?For example, Given n = 3, there are a total of 5 unique BST’s.解题思路使用一个一维数组来解决这个问题,数组cnt[i]表示[1,2...i]能构成多少种二
2016-11-20 21:16:31
299
原创 Coin Change - leetcode 322号题目个人题解
题目要求You are given coins of different denominations and a total amount of money amount. Write a function to compute the fewest number of coins that you need to make up that amount. If that amount of mon
2016-11-20 20:59:31
505
原创 Is Subsequence - leetcode 392号题目个人题解
题目要求Given a string s and a string t, check if s is subsequence of t.You may assume that there is only lower case English letters in both s and t. t is potentially a very long (length ~= 500,000) string
2016-11-20 20:46:19
301
原创 Combination Sum IV - leetcode 377号题目个人题解
题目要求Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2, 3]target = 4The possible
2016-11-20 20:29:47
374
原创 Partition Equal Subset Sum - leetcode 416号题目个人题解
题目要求Given a non-empty array containing only positive integers, find if the array can be partitioned into two subsets such that the sum of elements in both subsets is equal.解题思路这个问题,只要我们稍微做一下转化,它其实是一个背包
2016-11-20 20:10:13
416
原创 Edit Distance - leetcode 72号题目个人题解
题目要求Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You have the following 3 operations permitted on a word:a
2016-11-20 17:25:43
339
原创 Frog Jump - leetcode 403号题目个人题解
题目要求A frog is crossing a river. The river is divided into x units and at each unit there may or may not exist a stone. The frog can jump on a stone, but it must not jump into the water.Given a list of
2016-10-21 23:53:30
467
原创 A*搜索 - 八数码问题
问题描述八数码问题,简单地来描述是这样的:在一个九宫格内,填有1、2、3、4、5、6、7、8,八个阿拉伯数字,有一个格子为空白。就下面这样,这
2016-10-03 00:53:30
1361
原创 Kth Smallest Element in a BST - leetcode 230号题目个人题解
Kth Smallest Element in a BST - leetcode 230号题目个人题解题目要求Given a binary search tree, write a function kthSmallest to find the ***k***th smallest element in it.Note:You may assume k is always valid, 1 ≤ k
2016-09-28 20:33:39
449
1
原创 Add and Search Word - leetcode 221号题目个人题解
Add and Search Word - leetcode 221号题目个人题解题目要求Design a data structure that supports the following two operations:void addWord(word) bool search(word) search(word) can search a literal word or a regul
2016-09-08 01:57:52
509
原创 3Sum Closest - leetcode 16号题目个人题解
这是一道Medium难度的题目。题目的大概意思是:给出一个长度为n个整数的数组S,然后给出一个目标值target。要求找出数组中三个数相加,使得相加之和与给出的目标值最接近(可以相等)。首先,看到这个题,很自然的我们就会想要遍历数组中所有三个数字的组合,来找到会接近目标值的结果。这种做法虽然时间复杂度可能会很高,但是写起来却是最简单有效不容易出错的。有了解题的思路,我们来看如何实现。
2016-09-06 23:25:38
561
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅