leetcode
SherlockSheep
这个作者很懒,什么都没留下…
展开
-
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 · 426 阅读 · 0 评论 -
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 · 296 阅读 · 0 评论 -
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 · 228 阅读 · 0 评论 -
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 · 426 阅读 · 0 评论 -
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 · 228 阅读 · 0 评论 -
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 · 308 阅读 · 0 评论 -
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 · 348 阅读 · 0 评论 -
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 · 270 阅读 · 0 评论 -
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 · 353 阅读 · 2 评论 -
3Sum Closest - leetcode 16号题目个人题解
这是一道Medium难度的题目。题目的大概意思是:给出一个长度为n个整数的数组S,然后给出一个目标值target。要求找出数组中三个数相加,使得相加之和与给出的目标值最接近(可以相等)。首先,看到这个题,很自然的我们就会想要遍历数组中所有三个数字的组合,来找到会接近目标值的结果。这种做法虽然时间复杂度可能会很高,但是写起来却是最简单有效不容易出错的。有了解题的思路,我们来看如何实现。原创 2016-09-06 23:25:38 · 459 阅读 · 1 评论 -
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 · 297 阅读 · 0 评论