algorithm-design
Ulricalin
这个作者很懒,什么都没留下…
展开
-
Course Schedule (graph)
Course ScheduleThere are a total of n courses you have to take, labeled from 0 to n - 1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expre原创 2017-09-25 19:26:11 · 315 阅读 · 0 评论 -
752. Open the Lock
You have a lock in front of you with 4 circular wheels. Each wheel has 10 slots: ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’. The wheels can rotate freely and wrap around: for example we can turn原创 2017-12-26 21:51:27 · 326 阅读 · 0 评论 -
Best Time to Buy and Sell Stock l, II, lll
Say 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 share of the stock), d原创 2018-01-11 20:07:54 · 242 阅读 · 0 评论 -
62 63 Unique Paths l, ll
A robot is located at the top-left corner of a m x n grid (marked ‘Start’ in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the bo原创 2018-01-11 20:54:26 · 186 阅读 · 0 评论 -
688. Knight Probability in Chessboard
On an NxN chessboard, a knight starts at the r-th row and c-th column and attempts to make exactly K moves. The rows and columns are 0 indexed, so the top-left square is (0, 0), and the bottom-right s原创 2018-01-12 00:54:03 · 194 阅读 · 0 评论 -
743. Network Delay Time
There are N network nodes, labelled 1 to N.Given times, a list of travel times as directed edges times[i] = (u, v, w), where u is the source node, v is the target node, and w is the time it takes fo原创 2018-01-22 00:07:42 · 209 阅读 · 0 评论 -
738. Monotone Increasing Digits
Given a non-negative integer N, find the largest number that is less than or equal to N with monotone increasing digits.(Recall that an integer has monotone increasing digits if and only if each pai原创 2017-12-31 21:58:47 · 210 阅读 · 0 评论 -
241. Different Ways to Add Parentheses
Given a string of numbers and operators, return all possible results from computing all the different possible ways to group numbers and operators. The valid operators are +, - and *.Example 1In原创 2018-01-04 20:53:35 · 199 阅读 · 0 评论 -
证明HITTING SET 是NP完全
In the HITTING SET problem, we are given a family of sets {S1, S2, … , Sn} and a budget b, and we wish to find a set H of size show that HITTING SET is NP-complete.我们很容易就能把顶点覆盖规约到HITTING SET证明:v原创 2018-01-04 21:14:59 · 749 阅读 · 0 评论 -
748. Shortest Completing Word
Find the minimum length word from a given dictionary words, which has all the letters from the string licensePlate. Such a word is said to complete the given string licensePlateHere, for letters we ign原创 2017-12-20 00:24:54 · 253 阅读 · 0 评论 -
516. Longest Palindromic Subsequence(最长回文子序列)
Given a string s, find the longest palindromic subsequence’s length in s. You may assume that the maximum length of s is 1000.Example 1:Input:"bbbab"Output:4One possible longest palindromic subseque原创 2017-12-02 17:02:20 · 301 阅读 · 0 评论 -
Kth Largest Element in an Array
Kth Largest Element in an ArrayFind 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,原创 2017-09-17 17:51:19 · 268 阅读 · 0 评论 -
Course Schedule III
There are n different online courses numbered from 1 to n. Each course has some duration(course length) t and closed on dth day. A course should be taken continuously for t days and must be finished be原创 2017-10-20 00:02:36 · 268 阅读 · 0 评论 -
Redundant Connection
Redundant ConnectionIn this problem, a tree is an undirected graph that is connected and has no cycles.The given input is a graph that started as a tree with N nodes (with distinct values 1, 2, …, N),原创 2017-10-05 21:37:54 · 700 阅读 · 0 评论 -
Redundant Connection II
Redundant Connection IIIn this problem, a rooted tree is a directed graph such that, there is exactly one node (the root) for which all other nodes are descendants of this node, plus every node has exa原创 2017-10-15 21:55:52 · 893 阅读 · 1 评论 -
638. Shopping Offers
In LeetCode Store, there are some kinds of items to sell. Each item has a price.However, there are some special offers, and a special offer consists of one or more different kinds of items with a sale原创 2017-10-31 22:31:40 · 243 阅读 · 0 评论 -
474. Ones and Zeroes
In the computer world, use restricted resource you have to generate maximum benefit is what we always want to pursue.For now, suppose you are a dominator of m 0s and n 1s respectively. On the other han原创 2017-11-06 16:02:07 · 260 阅读 · 0 评论 -
718. Maximum Length of Repeated Subarray
Given two integer arrays A and B, return the maximum length of an subarray that appears in both arrays.Example 1:Input:A: [1,2,3,2,1]B: [3,2,1,4,7]Output: 3Explanation: The repeated subarray with原创 2017-11-16 20:09:40 · 217 阅读 · 0 评论 -
647. Palindromic Substrings
Given a string, your task is to count how many palindromic substrings in this string.The substrings with different start indexes or end indexes are counted as different substrings even they consist of原创 2017-12-01 21:43:00 · 225 阅读 · 0 评论 -
673. Number of Longest Increasing Subsequence
Given an unsorted array of integers, find the number of longest increasing subsequence.Example 1:Input: [1,3,5,4,7]Output: 2Explanation: The two longest increasing subsequence are [1, 3, 4, 7] and [1原创 2017-11-22 22:10:53 · 192 阅读 · 0 评论 -
【c++】求1-n的最小公倍数
要求实现 输入一个n (1 <= n <= 10000) 求能整除1-n的最小正整数,即最小公倍数 由于数可能比较大,输出结果mod987654321 eg. 输入:3 输出:6 (6是能整除1,2,3的最小正整数)Hint: 我们知道两个数a,b的最小公倍数是a∗bgcd(a,b)a∗bgcd(a,b)\frac{a*b}{gcd(a,...原创 2018-04-09 22:14:12 · 4980 阅读 · 0 评论